亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術(shù)文章
文章詳情頁

PHP基礎(chǔ)之函數(shù)7——?jiǎng)討B(tài)調(diào)用函數(shù)

瀏覽:6日期:2022-09-14 17:09:29
call_user_func

(PHP 4, PHP 5)

call_user_func?—?傳入一個(gè)參數(shù)來調(diào)用回調(diào)函數(shù)

說明mixed?call_user_func?(?callable?$callback?[,?mixed?$parameter?[,?mixed?$...?]] )

Calls the?callback?given by the first parameter and passes the remaining parameters as arguments.

參數(shù)callbackThe?callable?to be called.parameterZero or more parameters to be passed to the callback.

Note:

Note that the parameters for?call_user_func()?are not passed by reference.

Example #1?call_user_func()?example and references

<?phperror_reporting(E_ALL);function?increment(&$var){????$var++;}$a?=?0;call_user_func(’increment’,?$a);echo?$a.'n';call_user_func_array(’increment’,?array(&$a));?//?You?can?use?this?instead?before?PHP?5.3echo?$a.'n';?>

以上例程會(huì)輸出:

01?返回值

Returns the return value of the callback, or?FALSE?on error.

?范例

Example #2?call_user_func()?example

<?phpfunction?barber($type){????echo?'You?wanted?a?$type?haircut,?no?problemn';}call_user_func(’barber’,?'mushroom');call_user_func(’barber’,?'shave');?>

以上例程會(huì)輸出:

You wanted a mushroom haircut, no problemYou wanted a shave haircut, no problem

Example #3?call_user_func()?using namespace name

<?phpnamespace?Foobar;class?Foo?{????static?public?function?test()?{????????print?'Hello?world!n';????}}call_user_func(__NAMESPACE__?.’Foo::test’);?//?As?of?PHP?5.3.0call_user_func(array(__NAMESPACE__?.’Foo’,?’test’));?//?As?of?PHP?5.3.0?>

以上例程會(huì)輸出:

Hello world!Hello world!

Example #4 Using a class method with?call_user_func()

<?phpclass?myclass?{????static?function?say_hello()????{????????echo?'Hello!n';????}}$classname?=?'myclass';call_user_func(array($classname,?’say_hello’));call_user_func($classname?.’::say_hello’);?//?As?of?5.2.3$myobject?=?new?myclass();call_user_func(array($myobject,?’say_hello’));?>

以上例程會(huì)輸出:

Hello!Hello!Hello!

Example #5 Using lambda function with?call_user_func()

<?phpcall_user_func(function($arg)?{?print?'[$arg]n';?},?’test’);?/*?As?of?PHP?5.3.0?*/?>

以上例程會(huì)輸出:

[test]call_user_func_array

(PHP 4 >= 4.0.4, PHP 5)

call_user_func_array?— 傳入一個(gè)參數(shù)數(shù)組來調(diào)用回調(diào)函數(shù)

說明mixed?call_user_func_array?(?callable?$callback?,?array?$param_arr?)

Calls the?callback?given by the first parameter with the parameters in?param_arr.

參數(shù)callbackThe?callable?to be called.param_arrThe parameters to be passed to the callback, as an indexed array.返回值

Returns the return value of the callback, or?FALSE?on error.

范例

Example #1?call_user_func_array()?example

<?phpfunction?foobar($arg,?$arg2)?{????echo?__FUNCTION__,?'?got?$arg?and?$arg2n';}class?foo?{????function?bar($arg,?$arg2)?{????????echo?__METHOD__,?'?got?$arg?and?$arg2n';????}}//?Call?the?foobar()?function?with?2?argumentscall_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 twofoo::bar got three and four

Example #2?call_user_func_array()?using namespace name

<?phpnamespace?Foobar;class?Foo?{????static?public?function?test($name)?{????????print?'Hello?{$name}!n';????}}//?As?of?PHP?5.3.0call_user_func_array(__NAMESPACE__?.’Foo::test’,?array(’Hannes’));//?As?of?PHP?5.3.0call_user_func_array(array(__NAMESPACE__?.’Foo’,?’test’),?array(’Philip’));?>

以上例程的輸出類似于:

Hello Hannes!Hello Philip!

Example #3 Using lambda function

<?php$func?=?function($arg1,?$arg2)?{????return?$arg1?*?$arg2;};var_dump(call_user_func_array($func,?array(2,?4)));?/*?As?of?PHP?5.3.0?*/?>

以上例程會(huì)輸出:

int(8)

標(biāo)簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 毛片网站视频 | 欧美一级淫片免费播放口 | 91亚洲国产成人久久精品网站 | 91成人国产网站在线观看 | 亚洲国产高清视频在线观看 | 三级网站大全 | a男人的天堂久久a毛片 | 国产午夜永久福利视频在线观看 | 成人免费视频社区 | 亚洲美女在线观看 | 亚洲欧美一区二区三区不卡 | 萌白酱粉嫩jk福利在线观看 | 成年人免费看视频 | 成人网视频在线观看免费 | 亚洲精品国产一区二区三区四区 | 一色屋成人免费精品网 | 国产一区2区 | 亚洲第一网站 | 国产网红自拍 | 91亚洲精品久久91 | 日韩欧美在线观看视频一区二区 | 国产精品久久久久久久 | 免费视频99| 日本欧美做爰全免费的视频 | 亚州中文字幕 | 国产下药迷倒白嫩丰满美女j8 | 日本一线一区二区三区免费视频 | 日韩欧美黄色 | 国产精品大全国产精品 | 国产成人深夜福利短视频99 | 操操综合 | 一区二区三区在线 | 欧 | 国产看片一区二区三区 | 欧美jizzhd精品欧美另类 | 欧美在线观看一区 | 欧美成人乱弄视频 | 在线播放日韩 | 天天拍拍夜夜出水 | 污美女网站www在线观看 | 久久精品国产亚洲7777 | 亚欧在线视频 |