Annotation of embedaddon/php/ext/standard/tests/array/array_walk_variation6.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_walk() function : usage variations - 'input' argument as diff. associative arrays
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
                      6:  * Description: Apply a user function to every member of an array 
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11:  * Passing 'input' argument as an associative array 
                     12:  *    with Numeric & string keys
                     13: */
                     14: 
                     15: echo "*** Testing array_walk() : 'input' as an associative array ***\n";
                     16: 
                     17: // callback functions
                     18: /* Prototype : for_numeric( int $value, int $key, int $user_data)
                     19:  * Parameters : $value - value from key/value pair of the array 
                     20:  *              $key - key from key/value pair of the array
                     21:  *              $user_data - data to be added to 'value'
                     22:  * Description : Function adds values with keys & user_data
                     23:  */
                     24: function for_numeric($value, $key, $user_data)
                     25: {
                     26:   // dump the input values to see if they are 
                     27:   // passed with correct type
                     28:   var_dump($key);
                     29:   var_dump($value);
                     30:   var_dump($user_data);
                     31:   echo "\n"; // new line to separate the output between each element
                     32: }
                     33: 
                     34: /* Prototype : for_string( string $value, string $key)
                     35:  * Parameters : $value - values in given input array
                     36:  *              $key - keys in given input array
                     37:  * Description : Function appends key to the value
                     38:  */
                     39: function for_string($value, $key)
                     40: {
                     41:   // dump the input values to see if they are 
                     42:   // passed with correct type
                     43:   var_dump($key);
                     44:   var_dump($value);
                     45:   echo "\n"; // new line to separate the output between each element
                     46: }
                     47: 
                     48: /* Prototype : for_mixed( mixed $value, mixed $key)
                     49:  * Parameters : $value - values in given input array
                     50:  *              $key - keys in given input array
                     51:  * Description : Function displays each element of an array with keys
                     52:  */
                     53: function for_mixed($value, $key)
                     54: {
                     55:   // dump the input values to see if they are 
                     56:   // passed with correct type
                     57:   var_dump($key);
                     58:   var_dump($value);
                     59:   echo "\n"; // new line to separate the output between each element
                     60: }
                     61: 
                     62: // Numeric keys
                     63: $input = array( 1 => 25, 5 => 12, 0 => -80, -2 => 100, 5 => 30);
                     64: echo "-- Associative array with numeric keys --\n";
                     65: var_dump( array_walk($input, "for_numeric", 10));
                     66: 
                     67: // String keys
                     68: $input = array( "a" => "Apple", 'b' => 'Bananna', "c" => "carrot", 'o' => "Orange");
                     69: echo "-- Associative array with string keys --\n";
                     70: var_dump( array_walk($input, "for_string"));
                     71: 
                     72: // binary keys
                     73: $input = array( b"a" => "Apple", b"b" => "Banana");
                     74: echo "-- Associative array with binary keys --\n";
                     75: var_dump( array_walk($input, "for_string"));
                     76: 
                     77: // Mixed keys - numeric/string
                     78: $input = array( 0 => 1, 1 => 2, "a" => "Apple", "b" => "Banana", 2 =>3);
                     79: echo "-- Associative array with numeric/string keys --\n";
                     80: var_dump( array_walk($input, "for_mixed"));
                     81: 
                     82: echo "Done"
                     83: ?>
                     84: --EXPECTF--
                     85: *** Testing array_walk() : 'input' as an associative array ***
                     86: -- Associative array with numeric keys --
                     87: int(1)
                     88: int(25)
                     89: int(10)
                     90: 
                     91: int(5)
                     92: int(30)
                     93: int(10)
                     94: 
                     95: int(0)
                     96: int(-80)
                     97: int(10)
                     98: 
                     99: int(-2)
                    100: int(100)
                    101: int(10)
                    102: 
                    103: bool(true)
                    104: -- Associative array with string keys --
                    105: string(1) "a"
                    106: string(5) "Apple"
                    107: 
                    108: string(1) "b"
                    109: string(7) "Bananna"
                    110: 
                    111: string(1) "c"
                    112: string(6) "carrot"
                    113: 
                    114: string(1) "o"
                    115: string(6) "Orange"
                    116: 
                    117: bool(true)
                    118: -- Associative array with binary keys --
                    119: string(1) "a"
                    120: string(5) "Apple"
                    121: 
                    122: string(1) "b"
                    123: string(6) "Banana"
                    124: 
                    125: bool(true)
                    126: -- Associative array with numeric/string keys --
                    127: int(0)
                    128: int(1)
                    129: 
                    130: int(1)
                    131: int(2)
                    132: 
                    133: string(1) "a"
                    134: string(5) "Apple"
                    135: 
                    136: string(1) "b"
                    137: string(6) "Banana"
                    138: 
                    139: int(2)
                    140: int(3)
                    141: 
                    142: bool(true)
                    143: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>