I have a multidimensional array with following values
$array = array(
0 => array (
\"id\" => 1,
\"parent_id\" =&
You can use count with array_filter
function doSearch($id, array $array) {
$arr = array_filter($array, function ($var) use ($id){
if ($id === $var['parent_id']) {
return true;
}
});
return count($arr);
}
or shorter version
function doSearch($id, array $array) {
return count(array_filter($array, function($var) use ($id) {
return $id === $var['parent_id'];
}));
}
So basically it gets elements where $id is equal to parent_id and returns their count