Mike McCarron
  • Home
  • Profile
  • Portfolio
  • Resume
  • Services
  • Design Blog
  • News & Press
  • Contact
Today is
October 6th, 2008Client Login
Resources - Flowers

Design Blog

Switching Keys For Values In PHP Arrays

February 4th 2006

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

$sample = array('key' => 'value');
$sample = array_flip($sample);
$sample_value = array_search('key', $sample);
/*
Will Return = 'value'
*/
Today is
October 6th, 2008Client Login

Design Journal

15 Most Recent Blog Entries

The Perfectly Centered Container For Tableless CSS
Switching Keys For Values In PHP Arrays
Great Web Design Resource

By Month

March 2006 (1)
February 2006 (2)

By Category

PHP (1)
Design (1)
CSS (1)
Copyright © 2002-2008 Mike McCarron Design. Site Map | Contact | XHTML | CSS | RSS (MT)
Bottom Of The Page