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
Post a Comment