php get array key by value multidimensional – array_column — Return the values from a single column in the input array. PHP Multidimensional Array Searching (Find key by specific value).
php get array key by value multidimensional
multidimensional array search refers to searching a value in a multilevel nested array. PHP multidimensional array search by value.
$member_names = array_column($membersList, 'name'); $emails = array_map(function ($ar) {return $ar['email'];}, $membersList);
Example
'krunal', 'email' => '[email protected]' ], [ 'name' => 'Ankit', 'email' => '[email protected]' ], [ 'name' => 'Dinesh', 'email' => '[email protected]' ], ]; $member_names = array_column($membersList, 'name'); $emails = array_map(function ($ar) {return $ar['email'];}, $membersList); print_r($member_names); print_r($emails); ?>
Result
Array ( [0] => krunal [1] => Ankit [2] => Dinesh ) Array ( [0] => [email protected] [1] => [email protected] [2] => [email protected] )
Don’t Miss : PHP Multidimensional Array Check If Specific Array Key
PHP multidimensional array search by value
function getProductDate($items, $field, $value) { foreach($items as $key => $item) { if ( $item[$field] === $value ) return $key; } return false; }
PHP Multidimensional Array Search By Value Example
"1", "name" => "Dev", "email" => "[email protected]" ], [ "id" => "2", "name" => "sachin", "email" => "[email protected]" ], [ "id" => "3", "name" => "Pankil", "email" => "[email protected]" ], [ "id" => "4", "name" => "Krunal", "email" => "[email protected]" ] ]; $playersAddress = [ [ "member_id" => "3", "address" => "Surat, Kolkata, India" ], [ "member_id" => "1", "address" => "Ahemdabad, Kolkata, India" ] ]; ?>PHP Multidimensional Array Search By Value Example - www.pakainfo.com
ID | Name | Address | |
I hope you get an idea about php get array key by value multidimensional.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.