In this tutorial I will describe that how you can search any value in multidimensional array in PHP.
I am taking an example to describe this. Like-
I want to fetch 'salary' with the name 'xyz' employee from an user array list.
$arr1=array(array('id'=>'0','name'=>'abc', 'salary' => '$10000'), array('id'=>'1','name'=>'stu', 'salary' => '$15000'), array('id'=>'2','name'=>'xyz', 'salary' => '$9500'), array('id'=>'3','name'=>'vwx', 'salary' => '$8257'));
$key = array_search("xyz", array_column($arr1,'name'));
echo 'salary of xyz: '.$arr1[$key]['salary'];
First I fetch the key of 'xyz' employee record then I fetch the 'salary value of that record.
0 Comment(s)