PHP function of the day: array_flip()

For day 15 of 21 in the “PHP Function of the day” series, I’m going to look at array_flip(). As you might guess, this function “flips” the array so that the key is the value and the value is the key.

Let’s take a look.

<?php

$joe = array(“fname”=>”Joe”,”lname”=>”Steinbring”,”website”=>”jws.dev”);

print_r($joe);

echo(“<br />”);

print_r(array_flip($joe));

echo(“<br /><br />”);

$foods = array(“Beans”, “Apples”, “Wine”, “Pizza”);

print_r($foods);

echo(“<br />”);

print_r(array_flip($foods));

?>

 

See the output

 

You might have noticed that I missed this past Thursday and Friday’s posts.  I took an extended weekend, so I am posting them on Monday.  There should be just one week of these PHP function posts left.

Leave a Reply

Your email address will not be published. Required fields are marked *