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));
?>
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.