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

1.1       misho       1: --TEST--
                      2: Test array_walk_recursive() function : usage variations - 'input' argument containing reference variables
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool array_walk_recursive(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:  * Testing array_walk_recursive() with an array having reference variables
                     12: */
                     13: 
                     14: echo "*** Testing array_walk_recursive() : array with references ***\n";
                     15: 
                     16: $value1 = 10;
                     17: $value2 = -20;
                     18: $value3 = &$value1;
                     19: $value4 = 50;
                     20: 
                     21: // 'input' array containing references to above variables
                     22: $input = array(&$value1, array(&$value2, -35), array(&$value3, 0), array(&$value4));
                     23: 
                     24: // callback function
                     25: /* Prototype : callback(int $value, mixed $key)
                     26:  * Parameters : $value - values in given input array
                     27:  *              $key - keys in given input array
                     28:  * Description : function checks for the value whether positive or negative and displays according to that
                     29:  */
                     30: function callback($value, $key)
                     31: {
                     32:    // dump the arguments to check that they are passed
                     33:    // with proper type
                     34:    var_dump($key);  // key
                     35:    var_dump($value); // value
                     36:    echo "\n"; // new line to separate the output between each element
                     37: }
                     38: 
                     39: var_dump( array_walk_recursive($input, "callback"));
                     40: 
                     41: echo "Done"
                     42: ?>
                     43: --EXPECTF--
                     44: *** Testing array_walk_recursive() : array with references ***
                     45: int(0)
                     46: int(10)
                     47: 
                     48: int(0)
                     49: int(-20)
                     50: 
                     51: int(1)
                     52: int(-35)
                     53: 
                     54: int(0)
                     55: int(10)
                     56: 
                     57: int(1)
                     58: int(0)
                     59: 
                     60: int(0)
                     61: int(50)
                     62: 
                     63: bool(true)
                     64: Done

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