diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/array/array_search_variation2.phpt | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/standard/tests/array/array_search_variation2.phpt')
-rw-r--r-- | ext/standard/tests/array/array_search_variation2.phpt | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_search_variation2.phpt b/ext/standard/tests/array/array_search_variation2.phpt new file mode 100644 index 0000000..da90de0 --- /dev/null +++ b/ext/standard/tests/array/array_search_variation2.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test array_search() function : usage variations - different haystack values +--FILE-- +<?php +/* + * Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise + * Source Code: ext/standard/array.c +*/ + +/* Test array_search() with different possible haystack values */ + +echo "*** Testing array_search() with different haystack values ***\n"; + +$misc_array = array ( + 'a', + 'key' =>'d', + 3, + ".001" =>-67, + "-.051" =>"k", + 0.091 =>"-.08", + "e" =>"5", + "y" =>NULL, + NULL =>"", + 0, + TRUE, + FALSE, + -27.39999999999, + " ", + "abcd\x00abcd\x00\abcd\x00abcdefghij", + "abcd\nabcd\tabcd\rabcd\0abcd" +); +$array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", ""); +/* loop to do loose and strict type check of elements in + $array_type on elements in $misc_array using array_search(); + checking PHP type comparison tables +*/ +$counter = 1; +foreach($array_type as $type) { + echo "-- Iteration $counter --\n"; + //loose type checking + var_dump( array_search($type,$misc_array ) ); + //strict type checking + var_dump( array_search($type,$misc_array,true) ); + //loose type checking + var_dump( array_search($type,$misc_array,false) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_search() with different haystack values *** +-- Iteration 1 -- +int(0) +int(3) +int(0) +-- Iteration 2 -- +string(1) "y" +int(4) +string(1) "y" +-- Iteration 3 -- +int(3) +bool(false) +int(3) +-- Iteration 4 -- +string(3) "key" +int(2) +string(3) "key" +-- Iteration 5 -- +int(3) +bool(false) +int(3) +-- Iteration 6 -- +int(3) +bool(false) +int(3) +-- Iteration 7 -- +int(2) +bool(false) +int(2) +-- Iteration 8 -- +int(3) +bool(false) +int(3) +-- Iteration 9 -- +string(1) "y" +string(1) "y" +string(1) "y" +-- Iteration 10 -- +string(1) "y" +bool(false) +string(1) "y" +-- Iteration 11 -- +int(2) +bool(false) +int(2) +-- Iteration 12 -- +string(1) "y" +string(0) "" +string(1) "y" +Done |