사이트 내 전체검색
PHP
[php] [Function] array_walk()
로빈아빠
https://cmd.kr/php/544 URL이 복사되었습니다.

본문

[Function] array_walk()

bool array_walk ( array &$array , callback $funcname [, mixed $userdata ] )
배열을 받아서 각각의 원소에 정의된 함수를 실행 시킨다.
각각의 원소에 동일한 작업을 반복시킬때 사용하시면 됩니다.
예를 들어 배열의 원소값에 맞는 인덱스를 찾을 때...

예)
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");

function test_alter(&$item1, $key, $prefix)
{
    $item1 = "$prefix: $item1";
}

function test_print($item2, $key)
{
    echo "$key. $item2<br />\n";
}

echo "Before ...:\n";
array_walk($fruits, 'test_print');

array_walk($fruits, 'test_alter', 'fruit');
echo "... and after:\n";

array_walk($fruits, 'test_print');
?>


출력 :
Before ...: d. lemon a. orange b. banana c. apple ... and after: d. fruit: lemon a. fruit: orange b. fruit: banana c. fruit: apple

댓글목록

등록된 댓글이 없습니다.

PHP
871 (9/18P)

Search

Copyright © Cmd 명령어 3.140.255.27