Search code examples
phparraysassociative-array

How to check given value present in nested array in PHP?


I am very new to the PHP, i want to check the value is present inside the associative array,please help me to acheive this thing.

public $array=[
  'id','name',
  'value.details'=>['type'=>'myFunction']
];
foreach($array as $key=>$condition){
if(in_array('myFunction',$array)){
//My logic
}
}

Solution

  • if you know the keys: if($array['value.details']['type'] === 'myFunction') { }

    if you walk through your array:

    foreach($array as $key=>$val) {
        if(is_array($val) && in_array('myFunction', $val)) {
            //
        }
    }