Deleted Added
full compact
array_walk_basic2.phpt (3e94ce6a) array_walk_basic2.phpt (04145dc2)
1tree 3e94ce6a:
1--TEST--
2Test array_walk() function : basic functionality - associative array
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*/
2
9
3.gdbinit
4CODING_STANDARDS
5CREDITS
6ChangeLog
7ChangeLog.1999.gz
8ChangeLog.2000.gz
9ChangeLog.2001.gz
10ChangeLog.2002.gz
11ChangeLog.2003.gz
12ChangeLog.2004.gz
13EXTENSIONS
14INSTALL
15LICENSE
16Makefile.frag
17Makefile.gcov
18Makefile.global
19NEWS
20README.CVS-RULES
21README.EXTENSIONS
22README.EXT_SKEL
23README.PARAMETER_PARSING_API
24README.PHP4-TO-PHP5-THIN-CHANGES
25README.QNX
26README.SELF-CONTAINED-EXTENSIONS
27README.STREAMS
28README.SUBMITTING_PATCH
29README.TESTING
30README.TESTING2
31README.UNIX-BUILD-SYSTEM
32README.UPDATE_5_2
33README.WIN32-BUILD-SYSTEM
34README.Zeus
35README.input_filter
36TODO
37TODO-5.1
38TODO-PHP5
39UPGRADING
40acconfig.h.in
41acinclude.m4
42buildconf
43buildconf.bat
44config.guess
45config.sub
46configure.in
47cvsclean
48cvsclean.bat
49footer
50genfiles
51header
52ltmain.sh
53makedist
54makerpm
55php.gif
56php.ini-dist
57php.ini-recommended
58php5.spec.in
59run-tests.php
60server-tests-config.php
61server-tests.php
62snapshot
63stamp-h.in
64stub.c
10echo "*** Testing array_walk() : basic functionality ***\n";
11
12// associative array
13$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
14
15// User defined callback functions
16/* Prototype : test_alter(mixed $item, mixed $key, string $prefix)
17 * Parameters : item - value in key/value pair
18 * key - key in key/value pair
19 * prefix - string to be added
20 * Description : alters the array values by appending prefix string
21 */
22function test_alter(&$item, $key, $prefix)
23{
24 // dump the arguments to check that they are passed
25 // with proper type
26 var_dump($item); // value
27 var_dump($key); // key
28 var_dump($prefix); // additional argument passed to callback function
29 echo "\n"; // new line to separate the output between each element
30}
31
32/* Prototype : test_print(mixed $item, mixed $key)
33 * Parameters : item - value in key/value pair
34 * key - key in key/value pair
35 * Description : prints the array values with keys
36 */
37function test_print($item, $key)
38{
39 // dump the arguments to check that they are passed
40 // with proper type
41 var_dump($item); // value
42 var_dump($key); // key
43 echo "\n"; // new line to separate the output between each element
44}
45
46echo "-- Using array_walk with default parameters to show array contents --\n";
47var_dump(array_walk($fruits, 'test_print'));
48
49echo "-- Using array_walk with one optional parameter to modify contents --\n";
50var_dump (array_walk($fruits, 'test_alter', 'fruit'));
51
52echo "-- Using array_walk with default parameters to show modified array contents --\n";
53var_dump (array_walk($fruits, 'test_print'));
54
55echo "Done";
56?>
57--EXPECT--
58*** Testing array_walk() : basic functionality ***
59-- Using array_walk with default parameters to show array contents --
60string(5) "lemon"
61string(1) "d"
62
63string(6) "orange"
64string(1) "a"
65
66string(6) "banana"
67string(1) "b"
68
69string(5) "apple"
70string(1) "c"
71
72bool(true)
73-- Using array_walk with one optional parameter to modify contents --
74string(5) "lemon"
75string(1) "d"
76string(5) "fruit"
77
78string(6) "orange"
79string(1) "a"
80string(5) "fruit"
81
82string(6) "banana"
83string(1) "b"
84string(5) "fruit"
85
86string(5) "apple"
87string(1) "c"
88string(5) "fruit"
89
90bool(true)
91-- Using array_walk with default parameters to show modified array contents --
92string(5) "lemon"
93string(1) "d"
94
95string(6) "orange"
96string(1) "a"
97
98string(6) "banana"
99string(1) "b"
100
101string(5) "apple"
102string(1) "c"
103
104bool(true)
105Done