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

1.1       misho       1: --TEST--
                      2: Test array_walk() function : usage variations - different callback functions
                      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 different types of callback functions to array_walk()
                     12:  *   without parameters
                     13:  *   with less and more parameters
                     14: */
                     15: 
                     16: echo "*** Testing array_walk() : callback function variation ***\n";
                     17: 
                     18: $input = array('Apple', 'Banana', 'Mango', 'Orange');
                     19: 
                     20: echo "-- callback function with both parameters --\n";
                     21: function callback_two_parameter($value, $key)
                     22: {
                     23:    // dump the arguments to check that they are passed
                     24:    // with proper type
                     25:    var_dump($key);  // key
                     26:    var_dump($value); // value
                     27:    echo "\n"; // new line to separate the output between each element
                     28: }
                     29: var_dump( array_walk($input, 'callback_two_parameter'));
                     30: 
                     31: echo "-- callback function with only one parameter --\n";
                     32: function callback_one_parameter($value)
                     33: {
                     34:    // dump the arguments to check that they are passed
                     35:    // with proper type
                     36:    var_dump($value); // value
                     37:    echo "\n"; // new line to separate the output between each element
                     38: }
                     39: var_dump( array_walk($input, 'callback_one_parameter'));
                     40: 
                     41: echo "-- callback function without parameters --\n";
                     42: function callback_no_parameter()
                     43: {
                     44:   echo "callback3() called\n";
                     45: }
                     46: var_dump( array_walk($input, 'callback_no_parameter'));
                     47: 
                     48: echo "-- passing one more parameter to function with two parameters --\n";
                     49: var_dump( array_walk($input, 'callback_two_parameter', 10)); 
                     50: 
                     51: echo "Done"
                     52: ?>
                     53: --EXPECTF--
                     54: *** Testing array_walk() : callback function variation ***
                     55: -- callback function with both parameters --
                     56: int(0)
                     57: string(5) "Apple"
                     58: 
                     59: int(1)
                     60: string(6) "Banana"
                     61: 
                     62: int(2)
                     63: string(5) "Mango"
                     64: 
                     65: int(3)
                     66: string(6) "Orange"
                     67: 
                     68: bool(true)
                     69: -- callback function with only one parameter --
                     70: string(5) "Apple"
                     71: 
                     72: string(6) "Banana"
                     73: 
                     74: string(5) "Mango"
                     75: 
                     76: string(6) "Orange"
                     77: 
                     78: bool(true)
                     79: -- callback function without parameters --
                     80: callback3() called
                     81: callback3() called
                     82: callback3() called
                     83: callback3() called
                     84: bool(true)
                     85: -- passing one more parameter to function with two parameters --
                     86: int(0)
                     87: string(5) "Apple"
                     88: 
                     89: int(1)
                     90: string(6) "Banana"
                     91: 
                     92: int(2)
                     93: string(5) "Mango"
                     94: 
                     95: int(3)
                     96: string(6) "Orange"
                     97: 
                     98: bool(true)
                     99: Done

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