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

1.1       misho       1: --TEST--
                      2: Test array_filter() function : usage variations - Different types of 'callback' function
                      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 types of callback functions to array_filter()
                     12: * with parameters and return
                     13: * without parameter and with return
                     14: * with parameter and without return
                     15: * without parameter and without return
                     16: */
                     17: 
                     18: echo "*** Testing array_filter() : usage variation - different 'callback' functions***\n";
                     19: 
                     20: // Initialize variables
                     21: $input = array(0, -1, 2, 3.4E-3, 'hello', "value", "key" => 4, 'null' => NULL);
                     22: 
                     23: // callback function without parameters and with return value
                     24: function callback1()
                     25: {
                     26:   return 1;
                     27: }
                     28: echo "-- Callback function without parameter and with return --\n";
                     29: var_dump( array_filter($input, "callback1") );
                     30: 
                     31: // callback function with parameter and without return value
                     32: function callback2($input)
                     33: {
                     34: }
                     35: echo "-- Callback funciton with parameter and without return --\n";
                     36: var_dump( array_filter($input, "callback2") );
                     37: 
                     38: 
                     39: // callback function without parameter and without return value
                     40: function callback3()
                     41: {
                     42: }
                     43: echo "-- Callback function without parameter and return --\n";
                     44: var_dump( array_filter($input, "callback3") );
                     45: 
                     46: // callback function with parameter and with return value
                     47: function callback4($input)
                     48: {
                     49:   if($input > 0 ) { 
                     50:     return true;
                     51:   }
                     52:   else {
                     53:     return false;
                     54:   }
                     55: }
                     56: echo "-- Callback function with parameter and return --\n";
                     57: var_dump( array_filter($input, "callback4") );
                     58: 
                     59: echo "Done"
                     60: ?>
                     61: --EXPECTF--
                     62: *** Testing array_filter() : usage variation - different 'callback' functions***
                     63: -- Callback function without parameter and with return --
                     64: array(8) {
                     65:   [0]=>
                     66:   int(0)
                     67:   [1]=>
                     68:   int(-1)
                     69:   [2]=>
                     70:   int(2)
                     71:   [3]=>
                     72:   float(0.0034)
                     73:   [4]=>
                     74:   string(5) "hello"
                     75:   [5]=>
                     76:   string(5) "value"
                     77:   ["key"]=>
                     78:   int(4)
                     79:   ["null"]=>
                     80:   NULL
                     81: }
                     82: -- Callback funciton with parameter and without return --
                     83: array(0) {
                     84: }
                     85: -- Callback function without parameter and return --
                     86: array(0) {
                     87: }
                     88: -- Callback function with parameter and return --
                     89: array(3) {
                     90:   [2]=>
                     91:   int(2)
                     92:   [3]=>
                     93:   float(0.0034)
                     94:   ["key"]=>
                     95:   int(4)
                     96: }
                     97: Done

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