I am trying to get the value from the array based on the key.
I have
$array1{
'0' =>'text1',
'1' =>'text2',
'2' =>'text3'
}
$array2{
'0' =>'123',
'1' =>'456',
'2' =>'789'
}
//$source could be text1,text2 or text3
//I want to show 123, 456 or 789 based on the value passed in
if(in_array($source, $array1)){
$id=array_keys($array1,$source);
echo $array2[$id];
}
I got an error saying ‘illegal offset type‘ becasue of $array2[$id].
Are there anyways to fix this? Thanks a lot!
I think you need array_search. Try: