I recently discovered a need to search an array for a value using PHP. The problem with the array_search() function is that it takes the value and an array as arguments and returns the key of the value found. Instead I had the key and needed to return the value. The problem was easily solved with the array_flip() function. The array_flip function switches the key with the value. This allowed me to use the array_search() functions to retrieve the values I wanted.
$sample = array('key' => 'value');
$sample = array_flip($sample);
$sample_value = array_search('key', $sample);
/*
Will Return = 'value'
*/
15 Most Recent Blog Entries
The Perfectly Centered Container For Tableless CSSBy Month
March 2006 (1)By Category
PHP (1)