String Combinations Matching
php, string
Solution
I would split your string into an array, and then compare it to an array of elements to match on.
$originalList = explode('_', 'a_b_c');
$matchList = array('a', 'b', 'c');
$diff = array_diff($matchList, $originalList);
if (!empty($diff)) {
// At least one of the elements in $matchList is not in $originalList
}
Beware of duplicate elements and what not, depending on how your data comes in.
Documentation:
- `array_diff()`
- `explode()`
Problem
Suppose a string: `$str = 'a_b_c';` I want match all possible combination with `a, b, c` with above. For example: `b_a_c`, `c_a_b`, `a_c_b`..etc will be give `true` when compare with above `$str`. NOTE: `$str` may be random. eg: `a_b`, `k_l_m_n` etc