2

i got array like:

array(512) {
[0]=>
  array(4) {
    ["@attributes"]=>
    array(4) {
      ["id"]=>
      string(4) "3048"
      ["net_id"]=>
      string(4) "1344"
      ["city_id"]=>
      string(3) "1021"     
    }    
    ["shop"]=>
    array(1) {
      ["@attributes"]=>
      array(1) {
        ["status"]=>
        string(6) "active"        
      }
    }
  }
  [1]=>
  array(2) {
    ["@attributes"]=>
    array(3) {
      ["id"]=>
      string(4) "2413"
      ["net_id"]=>
      string(4) "1093"
      ["city_id"]=>
      string(4) "1021"      
    }    
    ["shop"]=>
    array(1) {
      ["@attributes"]=>
      array(1) {
        ["status"]=>
        string(6) "active"
      }
    }
  }
  [2]=>
  array(2) {
    ["@attributes"]=>
    array(10) {
      ["id"]=>
      string(4) "2413"
      ["net_id"]=>
      string(4) "1093"
      ["city_id"]=>
      string(4) "1131"      
    }   
    ["shop"]=>
    array(1) {
      ["@attributes"]=>
      array(1) {
        ["status"]=>
        string(6) "active"
      }
    }
  }
}

And i need to find index of arrays by 'city_id' => '1021' for ex.

I find function for it. But its searching for only first match. How can i use it for multiple matching to get index of arrays with have $key => $value?

function array_find_deep($array, $search, $keys = array())
{
    foreach($array as $key => $value) {
        if (is_array($value)) {         
            $sub = array_find_deep($value, $search, array_merge($keys, array($key)));
            if (count($sub)) {
                return $sub;
            }
        } elseif ($value === $search) {         
            return array_merge($keys, array($key));
        }
    }

    return array();
}

0 Answers0