鏈枃妗d腑浣跨敤鐨勪吉绫诲瀷锛宮ixed 璇存槑涓涓弬鏁板彲浠ユ帴鍙楀绉嶄笉鍚岀殑锛堜絾骞朵笉蹇呴』鏄墍鏈夌殑锛夌被鍨嬨
鏈枃妗d腑浣跨敤鐨勪吉绫诲瀷
mixed 璇存槑涓涓弬鏁板彲浠ユ帴鍙楀绉嶄笉鍚岀殑锛堜絾骞朵笉蹇呴』鏄墍鏈夌殑锛夌被鍨嬨
渚嬪 gettype() 鍙互鎺ュ彈鎵鏈夌殑 PHP 绫诲瀷锛宻tr_replace() 鍙互鎺ュ彈瀛楃涓插拰鏁扮粍銆
number
number 璇存槑涓涓弬鏁板彲浠ユ槸 integer 鎴栬 float銆
callback
鏈変簺璇稿 call_user_function() 鎴 usort() 鐨勫嚱鏁版帴鍙楃敤鎴疯嚜瀹氫箟鐨勫嚱鏁颁綔涓轰竴涓弬鏁般侰allback 鍑芥暟涓嶄粎鍙互鏄竴涓畝鍗曠殑鍑芥暟锛屽畠杩樺彲浠ユ槸涓涓璞$殑鏂规硶锛屽寘鎷潤鎬佺被鐨勬柟娉曘
涓涓 PHP 鍑芥暟鐢ㄥ嚱鏁板悕瀛楃涓叉潵浼犻掋傚彲浠ヤ紶閫掍换浣曞唴缃殑鎴栬呯敤鎴疯嚜瀹氫箟鐨勫嚱鏁帮紝闄や簡璇█缁撴瀯濡 array()锛宔cho()锛宔mpty()锛宔val()锛宔xit()锛宨sset()锛宭ist()锛宲rint() 鍜 unset()銆
涓涓璞$殑鏂规硶浠ユ暟缁勭殑褰㈠紡鏉ヤ紶閫掞紝鏁扮粍鐨勪笅鏍 0 鎸囨槑瀵硅薄鍚嶏紝涓嬫爣 1 鎸囨槑鏂规硶鍚嶃
瀵逛簬娌℃湁瀹炰緥鍖栦负瀵硅薄鐨勯潤鎬佺被锛岃浼犻掑叾鏂规硶锛屽皢鏁扮粍 0 涓嬫爣鎸囨槑鐨勫璞″悕鎹㈡垚璇ョ被鐨勫悕绉板嵆鍙
闄や簡鏅氱殑鐢ㄦ埛瀹氫箟鐨勫嚱鏁板锛屼篃鍙互浣跨敤create_function()鏉ュ垱寤轰竴涓尶鍚嶇殑鍥炶皟鍑芥暟(callback)銆
Example #1 鍥炶皟鍑芥暟(callback)绀轰緥
<?php
// 鏅氱殑鍥炶皟鍑芥暟
function my_callback_function() {
echo 'hello world!';
}
// 鍥炶皟鏂规硶
class MyClass {
static function myCallbackMethod() {
echo 'Hello World!';
}
}
// Type 1: Simple callback
call_user_func('my_callback_function');
// Type 2: Static class method call
call_user_func(array('MyClass', 'myCallbackMethod'));
// Type 3: Object method call
$obj = new MyClass();
call_user_func(array($obj, 'myCallbackMethod'));
// Type 4: Static class method call (As of PHP 5.2.3)
call_user_func('MyClass::myCallbackMethod');
// Type 5: Relative static class method call (As of PHP 5.3.0)
class A {
public static function who() {
echo "A ";
}
}
class B extends A {
public static function who() {
echo "B ";
}
}
call_user_func(array('B', 'parent::who')); // A
?>
Note: 鍦 PHP4 涓紝蹇呴』浣跨敤寮曠敤鏉ュ垱寤轰竴涓寚鍚戝疄闄卭bject锛岃屼笉鏄畠鐨勪竴涓嫹璐濄傝鎯呰瑙佸紩鐢ㄧ殑瑙i噴銆 In PHP4, it was necessary to use a reference to create a callback that points to the actual object, and not a copy of it. For more details, see References Explained.
void
void 浣滀负杩斿洖绫诲瀷鎰忓懗鐫鍑芥暟鐨勮繑鍥炲兼槸鏃犵敤鐨勩倂oid浣滀负鍙傛暟鍒楄〃鎰忓懗鐫鍑芥暟涓嶆帴鍙椾换浣曞弬鏁般
...
鍦ㄥ嚱鏁板師鍨嬩腑锛$... 琛ㄧず绛夌瓑鐨勬剰鎬濄傚綋涓涓嚱鏁板彲浠ユ帴鍙椾换鎰忎釜鍙傛暟鏃朵娇鐢ㄦ鍙橀噺鍚嶃
浠ヤ笂灏辨槸PHP绫诲瀷涔嬫湰鏂囨。涓娇鐢ㄧ殑浼被鍨嬬殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒