PHP: How can I get the value from a key in a multiple array -


the multiple array looks like

array (     [id] => description     [header] =>      [width] => 20     [dbfield] => description     [type] => text ) array (     [id] => quantity     [header] => menge     [dbfield] => quantity_new     [width] => 60     [type] => decimal ) 

how can value dbfield id 'quantity' without knowing numeric value of id?

the actual code looks like

foreach($array $id => $fielddata) {     if($fielddata['type'] == 'decimal')     {      dosomething...();    } } 

in part dosomething need access other fields array, know id. tried dbfield['quantity']['dbfield'] etc. fails.

you can several methods, 1 of them using array_map values:

$dbfield = array_filter(array_map(function($a){     if($a["id"] === "quantity"){         return $a["dbfield"];     } }, $array));  print_r($dbfield); 

you iterate on array, , return key dbfield id 'quantity'. array filter not return null values doesn't have 'quantity' id.

online attempt reproduce code can found here


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -