Exact position of element in array

时间:2017-10-12 10:12:47

标签: php arrays

I am using below code to search string in array and print corresponding response code. But below code always print Approved1 in all cases (i.e. 000,00,0)

$resp_desc=["Approved1","Approved","Fail"];
$resp_table=["000","00","0"];
$description=array_search("0",array_keys($resp_table));
$desc1=$resp_desc[$description];
echo $desc1;

Please guide in above matter.

1 个答案:

答案 0 :(得分:3)

You are searching in the array keys not the values of the array, set restrict to true in the array_search so you have only one result

$description=array_search("0",$resp_table,true);