I have the following array:
$array = array(1=>'one', 2=>'two', 3=>'three');
I know it’s possible to use array_search(); to return “1” when searching for “one”, but how do I return “one” when searching for “1”?
I’ve tried $array[1], but this does not work. I’m guessing that’s because the array has => in each value, as it normally works without that.
EDIT: Sorry, it was my variable scope.
PHP’s arrays are used to point from keys to values. In your case
1is a key and"one"is a value. You need to usearray_searchwhen you’re trying to get a key from a value, but you’re just using an array normally so you can just do: