array(
[n] => array(
[mother] => 'some_name',
[children] => [n] => array(
['child_name']=>'some_name'
...
)
)
)
I would like to filter this array using the array_filter(). To filter that array to get only the "records" where the mothers are named "Jane" for instance I do the following which is working like a charm.
array_filter($myarray, function ($k) {
return $k['mother'] == 'Jane';
});
Now I would like to filter $myarray to get the "records" where the children are named "Peter". I tried the following which is not working.
array_filter($myarray, function ($k) {
return $k['children']$k['child_name'] == 'Peter';
});
I also tried the following which is not working either.
array_filter($myarray, function ($k1,$k2) {
return $k1['children']$k2['child_name'] == 'Peter';
});
array([child_name] => ...)
is invalid syntax. What does the array actually look like? – deceze Feb 24 '14 at 16:21print_r()
output I guess – Alma Do Feb 24 '14 at 16:22array_walk()
orarray_walk_recursive()
, or simply just build your own looping logic in a function. it is also not clear what you want to happen when the key/value is found in child array. Should that child array itself be filtered? – Mike Brant Feb 24 '14 at 16:59