1--TEST-- 2Test array_flip() function : usage variations - 'input' argument with repeatitive keys and values 3--FILE-- 4<?php 5/* Prototype : array array_flip(array $input) 6 * Description: Return array with key <-> value flipped 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11* Using different types of repeatitive keys as well as values for 'input' array 12*/ 13 14echo "*** Testing array_flip() : 'input' array with repeatitive keys/values ***\n"; 15 16// array with numeric key repeatition 17$input = array(1 => 'value', 2 => 'VALUE', 1 => "VaLuE", 3.4 => 4, 3.4 => 5); 18var_dump( array_flip($input) ); 19 20// array with string key repeatition 21$input = array("key" => 1, "two" => 'TWO', 'three' => 3, 'key' => "FOUR"); 22var_dump( array_flip($input) ); 23 24// array with bool key repeatition 25$input = array(true => 1, false => 0, TRUE => -1); 26var_dump( array_flip($input) ); 27 28// array with null key repeatition 29$input = array(null => "Hello", NULL => 0); 30var_dump( array_flip($input) ); 31 32// array with numeric value repeatition 33$input = array('one' => 1, 'two' => 2, 3 => 1, "index" => 1); 34var_dump( array_flip($input) ); 35 36//array with string value repeatition 37$input = array('key1' => "value1", "key2" => '2', 'key3' => 'value1'); 38var_dump( array_flip($input) ); 39 40echo "Done" 41?> 42--EXPECTF-- 43*** Testing array_flip() : 'input' array with repeatitive keys/values *** 44array(3) { 45 ["VaLuE"]=> 46 int(1) 47 ["VALUE"]=> 48 int(2) 49 [5]=> 50 int(3) 51} 52array(3) { 53 ["FOUR"]=> 54 string(3) "key" 55 ["TWO"]=> 56 string(3) "two" 57 [3]=> 58 string(5) "three" 59} 60array(2) { 61 [-1]=> 62 int(1) 63 [0]=> 64 int(0) 65} 66array(1) { 67 [0]=> 68 string(0) "" 69} 70array(2) { 71 [1]=> 72 string(5) "index" 73 [2]=> 74 string(3) "two" 75} 76array(2) { 77 ["value1"]=> 78 string(4) "key3" 79 [2]=> 80 string(4) "key2" 81} 82Done 83