PHP/Data Structure/array flip

Материал из Web эксперт
Перейти к: навигация, поиск

array_flip demo

   <source lang="html4strict">

<?php $state = array("A","P","N"); $state = array_flip($state); print_r($state); ?>

 </source>
   
  


array_flip() example

   <source lang="html4strict">

<? $trans = array(1, "hello", 1, "world", "hello"); $trans = array_flip ($trans); $original = strtr ($str, $trans); ?>

 </source>
   
  


array_flip( ) exchanges all the keys in that array with their matching values

   <source lang="html4strict">

<?

   $capitalcities["England"] = "London";
   $capitalcities["Scotland"] = "Edinburgh";
   $capitalcities["Wales"] = "Cardiff";
   $flippedcities = array_flip($capitalcities);
   var_dump($flippedcities);

?>

 </source>
   
  


array_flip() function exchanges all key and element values for the array.

   <source lang="html4strict">

//Its syntax is: array array_flip(array array) <?

   $l = array("a" => "A","b" => "B","q" => "Q");
   $l = array_flip($l);
   print_r($l);

?>

 </source>
   
  


Using array_flip() to return a string back to its original value

   <source lang="html4strict">

<?

   $string = "adsf";
   $translate = get_html_translation_table(HTML_ENTITIES);
   $translate = array_flip($translate);
   print_r($translate) ;

?>

 </source>