Iterating over a complex Associative Array in PHP

后端 未结 7 1875
广开言路
广开言路 2020-11-27 17:00

Is there an easy way to iterate over an associative array of this structure in PHP:

The array $searches has a numbered index, with between 4 and 5 assoc

相关标签:
7条回答
  • 2020-11-27 18:00

    Consider this multi dimentional array, I hope this function will help.

    $n = array('customer' => array('address' => 'Kenmore street',
                    'phone' => '121223'),
          'consumer' => 'wellington consumer',
          'employee' => array('name' => array('fname' => 'finau', 'lname' => 'kaufusi'),
                         'age' => 32,
                     'nationality' => 'Tonga')
          );
    
    
    
    iterator($n);
    
    function iterator($arr){
    
        foreach($arr as $key => $val){
    
        if(is_array($val))iterator($val);
    
        echo '<p>key: '.$key.' | value: '.$val.'</p>';
    
        //filter the $key and $val here and do what you want
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题