"PHP call user func array()"의 두 판 사이의 차이

4번째 줄: 4번째 줄:
* 파라미터 배열로 콜백함수를 호출하는 PHP 함수
* 파라미터 배열로 콜백함수를 호출하는 PHP 함수


<syntaxhighlight lang='php'>
<syntaxhighlight lang='php' run>
<?php
function foobar($arg, $arg2) {
function foobar($arg, $arg2) {
     echo __FUNCTION__, " got $arg and $arg2\n";
     echo __FUNCTION__, " got $arg and $arg2\n";
11번째 줄: 10번째 줄:
call_user_func_array("foobar", array("one", "two"));
call_user_func_array("foobar", array("one", "two"));
# foobar got one and two
# foobar got one and two
</syntaxhighlight>
<syntaxhighlight lang='php' run>
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"));
</syntaxhighlight>
</syntaxhighlight>



2021년 7월 18일 (일) 14:50 판

1 개요

PHP call_user_func_array()
  • 파라미터 배열로 콜백함수를 호출하는 PHP 함수
function foobar($arg, $arg2) {
    echo __FUNCTION__, " got $arg and $arg2\n";
}
call_user_func_array("foobar", array("one", "two"));
# foobar got one and two
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"));

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}