php array_map 배열 첨자 합치기
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
array_map — Applies the callback to the elements of the given arrays
array array_map ( callable $callback , array $array1 [, array $... ] )
<?php
function show_Spanish($n, $m)
{
return("The number $n is called $m in Spanish");
}
function map_Spanish($n, $m)
{
return(array($n => $m));
}
$a = array(1, 2, 3, 4, 5);
$b = array("uno", "dos", "tres", "cuatro", "cinco");
$c = array_map("show_Spanish", $a, $b);
print_r($c);
$d = array_map("map_Spanish", $a , $b);
print_r($d);
?>
// printout of $c
Array
(
[0] => The number 1 is called uno in Spanish
[1] => The number 2 is called dos in Spanish
[2] => The number 3 is called tres in Spanish
[3] => The number 4 is called cuatro in Spanish
[4] => The number 5 is called cinco in Spanish
)
// printout of $d
Array
(
[0] => Array
(
[1] => uno
)
[1] => Array
(
[2] => dos
)
[2] => Array
(
[3] => tres
)
[3] => Array
(
[4] => cuatro
)
[4] => Array
(
[5] => cinco
)
)
'IT > php' 카테고리의 다른 글
php array_unique php 배열 중복값 제거 하기 (0) | 2016.10.06 |
---|---|
php arsort 배열 첨자 기준 정렬 배열정렬 (0) | 2016.10.06 |
array_slice 배열자르기 (0) | 2016.10.06 |
php header charset uft-8 (0) | 2016.02.14 |
Fatal error: Allowed memory size of memory_limit (0) | 2016.02.14 |