From e4738deb2c360097aaa427e038a2bb74e5b52bb4 Mon Sep 17 00:00:00 2001 From: Damien Seguy Date: Wed, 16 May 2001 08:36:08 +0000 Subject: [PATCH] Added Thomas's contribution, plus more details on array_flip. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@47561 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/array.xml | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/functions/array.xml b/functions/array.xml index 9bb469d9af..76fd1dc67a 100644 --- a/functions/array.xml +++ b/functions/array.xml @@ -270,7 +270,20 @@ $even_arr = array_filter($array2, "even"); - Array_flip returns an array in flip order. + array_flip returns an array in flip order, + i.e. keys from trans become values and + trans's values become keys. + Note that array_flip works only with string + and integer values, and it will display an alert if it detects + invalid key or value (array, double, object, boolean). + + + If a value has several occurences, the latest key will be + used as its values, and all others will be lost. + + + array_flip returns FALSE + if it fails. @@ -281,6 +294,16 @@ $original = strtr ($str, $trans); + + + <function>Array_flip</function> example : collision + +$trans = array ("a" => 1, "b" => 1, "c" => 2); +$trans = array_flip ($trans); +// now $trans is : array(1 => "b", 2 => "c"); + + + @@ -1011,9 +1034,9 @@ $result_keyed = array_reverse ($input, TRUE); - This makes $result have array - (array ("green", "red"), 4.0, "php"). But - $result2[0] is still + This makes both $result and $result_keyed + be array(array ("green", "red"), 4.0, "php"). But + $result_keyed[0] is still "php".