php - Extract sub array resulting key=id and value=name in CakePHP -


i have nested array:

array (     [id] => 1     [name] => group 1     [0] => array         (             [id] => 1             [name] => group 1         )      [1] => array         (             [id] => 2             [name] => group 2         )      [2] => array         (             [id] => 7             [name] => group 7         )  ) 

and extract sub arrays [0], [1], , [2] in 1 single array following format:

array( [id] => [name] ) 

in other words have result:

array (     [1] => group 1     [2] => group 2     [7] => group 7 ) 

*note: tried set::classicextract($my_array['group'], '{n}.name'); can't figure out how group.id key array. guidance appreciated.

this should work you:

(here first array_filter() values out, don't have numeric key. after array_combine() id column name column array_column())

<?php      $result = array_filter($arr, function($k){         return is_numeric($k);     }, array_filter_use_key);      $result = array_combine(array_column($result, "id"), array_column($result, "name"));        print_r($result);  ?> 

output:

array ( [1] => group 1 [2] => group 2 [7] => group 7 ) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -