PHP/Data Structure/array flip

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

array_flip demo

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



array_flip() example

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



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

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



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

 
//Its syntax is: array array_flip(array array)
<?
    $l = array("a" => "A","b" => "B","q" => "Q");
    $l = array_flip($l);
    print_r($l);
?>



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

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