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

1.1       misho       1: --TEST--
                      2: Test array_key_exists() function : usage variations -  equality test for certain data types
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool array_key_exists(mixed $key, array $search)
                      6:  * Description: Checks if the given key or index exists in the array 
                      7:  * Source code: ext/standard/array.c
                      8:  * Alias to functions: key_exists
                      9:  */
                     10: 
                     11: /*
                     12:  * Pass certain data types that can be taken as a key in an array 
                     13:  * and test whether array_key_exists(() thinks they are equal and therefore
                     14:  * returns true when searching for them
                     15:  */
                     16: 
                     17: echo "*** Testing array_key_exists() : usage variations ***\n";
                     18: 
                     19: $unset = 10;
                     20: unset($unset);
                     21: $array = array ('null' => null, 
                     22:                 'NULL' => NULL, 
                     23:                 'empty single quoted string' => '', 
                     24:                 "empty double quoted string" => "", 
                     25:                 'undefined variable' => @$undefined,
                     26:                 'unset variable' => @$unset);
                     27: 
                     28: //iterate through original array
                     29: foreach($array as $name => $input) {
                     30:        $iterator = 1;
                     31:        echo "\n-- Key in \$search array is : $name --\n";
                     32:        $search[$input] = 'test';
                     33:        
                     34:        //iterate through array again to see which values are considered equal
                     35:        foreach($array as $key) {
                     36:                echo "Iteration $iterator:  ";
                     37:                var_dump(array_key_exists($key, $search));
                     38:                $iterator++;
                     39:        }
                     40:        $search = null;
                     41: }
                     42: 
                     43: echo "Done";
                     44: ?>
                     45: 
                     46: --EXPECTF--
                     47: *** Testing array_key_exists() : usage variations ***
                     48: 
                     49: -- Key in $search array is : null --
                     50: Iteration 1:  bool(true)
                     51: Iteration 2:  bool(true)
                     52: Iteration 3:  bool(true)
                     53: Iteration 4:  bool(true)
                     54: Iteration 5:  bool(true)
                     55: Iteration 6:  bool(true)
                     56: 
                     57: -- Key in $search array is : NULL --
                     58: Iteration 1:  bool(true)
                     59: Iteration 2:  bool(true)
                     60: Iteration 3:  bool(true)
                     61: Iteration 4:  bool(true)
                     62: Iteration 5:  bool(true)
                     63: Iteration 6:  bool(true)
                     64: 
                     65: -- Key in $search array is : empty single quoted string --
                     66: Iteration 1:  bool(true)
                     67: Iteration 2:  bool(true)
                     68: Iteration 3:  bool(true)
                     69: Iteration 4:  bool(true)
                     70: Iteration 5:  bool(true)
                     71: Iteration 6:  bool(true)
                     72: 
                     73: -- Key in $search array is : empty double quoted string --
                     74: Iteration 1:  bool(true)
                     75: Iteration 2:  bool(true)
                     76: Iteration 3:  bool(true)
                     77: Iteration 4:  bool(true)
                     78: Iteration 5:  bool(true)
                     79: Iteration 6:  bool(true)
                     80: 
                     81: -- Key in $search array is : undefined variable --
                     82: Iteration 1:  bool(true)
                     83: Iteration 2:  bool(true)
                     84: Iteration 3:  bool(true)
                     85: Iteration 4:  bool(true)
                     86: Iteration 5:  bool(true)
                     87: Iteration 6:  bool(true)
                     88: 
                     89: -- Key in $search array is : unset variable --
                     90: Iteration 1:  bool(true)
                     91: Iteration 2:  bool(true)
                     92: Iteration 3:  bool(true)
                     93: Iteration 4:  bool(true)
                     94: Iteration 5:  bool(true)
                     95: Iteration 6:  bool(true)
                     96: Done

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