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

1.1       misho       1: --TEST--
                      2: Test array_filter() function : usage variations - anonymous callback functions 
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_filter(array $input [, callback $callback])
                      6:  * Description: Filters elements from the array via the callback. 
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11: * Passing different anonymous callback functions with passed by value and reference arguments
                     12: */
                     13: 
                     14: echo "*** Testing array_filter() : usage variations - Anonymous callback functions ***\n";
                     15: 
                     16: $input = array(0, 1, -1, 10, 100, 1000, 'Hello', null);
                     17: 
                     18: // anonymous callback function
                     19: echo "Anonymous callback function with regular parameter and statement\n";
                     20: var_dump( array_filter($input, create_function('$input', 'return ($input > 1);') ) );
                     21: 
                     22: // anonymous callback function with reference
                     23: echo "Anonymous callback function with reference parameter\n";
                     24: var_dump( array_filter($input, create_function('&$input', 'return ($input < 1);') ) );
                     25: 
                     26: // anonymous callback function with null argument
                     27: echo "Anonymous callback funciton with null argument\n";
                     28: var_dump( array_filter($input, create_function(null, 'return true;') ) );
                     29: 
                     30: // anonymous callback function with argument and null statement
                     31: echo "Anonymous callback function with regular argument and null statement\n";
                     32: var_dump( array_filter($input, create_function('$input', null) ) );
                     33: 
                     34: echo "Done"
                     35: ?>
                     36: --EXPECTF--
                     37: *** Testing array_filter() : usage variations - Anonymous callback functions ***
                     38: Anonymous callback function with regular parameter and statement
                     39: array(3) {
                     40:   [3]=>
                     41:   int(10)
                     42:   [4]=>
                     43:   int(100)
                     44:   [5]=>
                     45:   int(1000)
                     46: }
                     47: Anonymous callback function with reference parameter
                     48: array(4) {
                     49:   [0]=>
                     50:   int(0)
                     51:   [2]=>
                     52:   int(-1)
                     53:   [6]=>
                     54:   string(5) "Hello"
                     55:   [7]=>
                     56:   NULL
                     57: }
                     58: Anonymous callback funciton with null argument
                     59: array(8) {
                     60:   [0]=>
                     61:   int(0)
                     62:   [1]=>
                     63:   int(1)
                     64:   [2]=>
                     65:   int(-1)
                     66:   [3]=>
                     67:   int(10)
                     68:   [4]=>
                     69:   int(100)
                     70:   [5]=>
                     71:   int(1000)
                     72:   [6]=>
                     73:   string(5) "Hello"
                     74:   [7]=>
                     75:   NULL
                     76: }
                     77: Anonymous callback function with regular argument and null statement
                     78: array(0) {
                     79: }
                     80: Done

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