????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.28 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/b8009/php-5.6.22/ext/standard/tests/array/ |
Upload File : |
--TEST--
Test array_map() function : usage variations - callback function with different return types
--FILE--
<?php
/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] )
* Description: Applies the callback to the elements of the given arrays
* Source code: ext/standard/array.c
*/
/*
* Test array_map() by passing different callback function returning:
* int, string, bool, null values
*/
echo "*** Testing array_map() : callback with diff return value ***\n";
$array1 = array(1, 2, 3);
$array2 = array(3, 4, 5);
echo "-- with integer return value --\n";
function callback_int($a, $b)
{
return $a + $b;
}
var_dump( array_map('callback_int', $array1, $array2));
echo "-- with string return value --\n";
function callback_string($a, $b)
{
return "$a"."$b";
}
var_dump( array_map('callback_string', $array1, $array2));
echo "-- with bool return value --\n";
function callback_bool($a, $b)
{
return TRUE;
}
var_dump( array_map('callback_bool', $array1, $array2));
echo "-- with null return value --\n";
function callback_null($array1)
{
return NULL;
}
var_dump( array_map('callback_null', $array1));
echo "-- with no return value --\n";
function callback_without_ret($arr1)
{
echo "callback_without_ret called\n";
}
var_dump( array_map('callback_without_ret', $array1));
echo "Done";
?>
--EXPECTF--
*** Testing array_map() : callback with diff return value ***
-- with integer return value --
array(3) {
[0]=>
int(4)
[1]=>
int(6)
[2]=>
int(8)
}
-- with string return value --
array(3) {
[0]=>
string(2) "13"
[1]=>
string(2) "24"
[2]=>
string(2) "35"
}
-- with bool return value --
array(3) {
[0]=>
bool(true)
[1]=>
bool(true)
[2]=>
bool(true)
}
-- with null return value --
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
-- with no return value --
callback_without_ret called
callback_without_ret called
callback_without_ret called
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
Done