how to get parent array index from multidimensional array in php

前端 未结 1 487
[愿得一人]
[愿得一人] 2021-01-27 07:54

I have an array $arr.

when I print this it shows the results as follows.

Array
(
    [0] => Array
        (
            [name] => homeandgarden-Con         


        
相关标签:
1条回答
  • 2021-01-27 07:56

    I think you are looking for this:

    function getIndex($name, $array){
        foreach($array as $key => $value){
            if(is_array($value) && $value['name'] == $name)
                  return $key;
        }
        return null;
    }
    
    0 讨论(0)
提交回复
热议问题