본문 바로가기

TroubleShooting/PHP

PHP함수 call_user_func_array()

728x90

mixed call_user_func_array ( callback $function , array $param_arr )

: 사용자 정의 함수 $function 을 파라미터 $param_arr 으로 호출한다.(callback)

<?php
function foobar($arg$arg2) {
    echo 
__FUNCTION__" got $arg and $arg2\n";
}
class 
foo {
    function 
bar($arg$arg2) {
        echo 
__METHOD__" got $arg and $arg2\n";
    }
}


// Call the foobar() function with 2 arguments
call_user_func_array("foobar", array("one""two"));

// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo"bar"), array("three""four"));
?>

=> 결과
foobar got one and two
foo::bar got three and four 

출처 : php.net 

'TroubleShooting > PHP' 카테고리의 다른 글

CentOS 5.6 에서 php 5.3 설치  (0) 2012.05.15
apm 설치  (0) 2011.11.14
HTML 안의 php 코드 인식  (0) 2011.05.27
goo.gl short URL API 사용  (0) 2011.03.11
php 문자열을 파일로 저장하는 예제  (0) 2011.02.26