无需言 做自己 业 ,精于勤 荒于嬉.
- 变量处理 函数 is_numeric 检测变量是否为数字或数字字符串
-
发表日期:2021-07-01 08:57:21 | 来源: | 分类:变量处理 函数
-
示例1
<?php $tests = array( "42", 1337, 0x539, 02471, 0b10100111001, 1337e0, "0x539", "02471", "0b10100111001", "1337e0", "not numeric", array(), 9.1, null, '',); foreach ($tests as $element) { if (is_numeric($element)) { echo var_export($element, true) . " is numeric", PHP_EOL; } else { echo var_export($element, true) . " is NOT numeric", PHP_EOL; } } ?>
- 变量处理 函数 boolval 获取变量的布尔值
-
发表日期:2021-07-01 08:57:20 | 来源: | 分类:变量处理 函数
-
示例1
<?php echo '0: '.(boolval(0) ? 'true' : 'false')."\n"; echo '42: '.(boolval(42) ? 'true' : 'false')."\n"; echo '0.0: '.(boolval(0.0) ? 'true' : 'false')."\n"; echo '4.2: '.(boolval(4.2) ? 'true' : 'false')."\n"; echo '"": '.(boolval("") ? 'true' : 'false')."\n"; echo '"string": '.(boolval("string") ? 'true' : 'false')."\n"; echo '"0": '.(boolval("0") ? 'true' : 'false')."\n"; echo '"1": '.(boolval("1") ? 'true' : 'false')."\n"; echo '[1, 2]: '.(boolval([1, 2]) ? 'true' : 'false')."\n"; echo '[]: '.(boolval([]) ? 'true' : 'false')."\n"; echo 'stdClass: '.(boolval(new stdClass) ? 'true' : 'false')."\n"; ?>
- 变量处理 函数 doubleval floatval() 的别名
-
发表日期:2021-07-01 08:57:20 | 来源: | 分类:变量处理 函数
-
描述
此函数是 floatval() 的别名。
注意:
此别名是函数改名之后的遗留问题。在 PHP 旧的版本中由于还没有 floatval() 函数,所以你可能需要用到这个 floatval() 的别名函数。
- 变量处理 函数 debug_zval_dump Dumps a string representation of an internal zval structure to output
-
发表日期:2021-07-01 08:57:20 | 来源: | 分类:变量处理 函数
-
示例1
<?php $var1 = 'Hello'; $var1 .= ' World'; $var2 = $var1; debug_zval_dump($var1); ?>
示例2
<?php $var1 = 'Hello'; $var1 .= ' World'; // Point three variables as references to the same value$var2 =& $var1; $var3 =& $var1; debug_zval_dump($var1); ?>
- 变量处理 函数 floatval 获取变量的浮点值
-
发表日期:2021-07-01 08:57:20 | 来源: | 分类:变量处理 函数
-
示例1
<?php $var = '122.34343The'; $float_value_of_var = floatval ($var); print $float_value_of_var; // 打印出 122.34343?>
- 函数处理 函数 call_user_func 把第一个参数作为回调函数调用
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php error_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"; ?>示例2
<?php function barber($type){ echo "You wanted a $type haircut, no problem\n"; } call_user_func('barber', "mushroom"); call_user_func('barber', "shave"); ?>示例3
<?php namespace 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?>示例4
<?php class 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')); ?>示例5
<?php call_user_func(function($arg) { print "[$arg]\n"; } , 'test'); /* As of PHP 5.3.0 */ ?>
- 函数处理 函数 func_num_args Returns the number of arguments passed to the function
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php function foo(){ $numargs = func_num_args(); echo "Number of arguments: $numargs\n"; } foo(1, 2, 3); ?>示例2
test.php<?php function foo() { include './fna.php'; } foo('First arg', 'Second arg'); ?>fna.php<?php$num_args = func_num_args(); var_export($num_args); ?>
- 函数处理 函数 get_defined_functions 返回所有已定义函数的数组
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php function myrow($id, $data){ return "<tr><th>$id</th><td>$data</td></tr>\n"; } $arr = get_defined_functions(); print_r($arr); ?>
- 函数处理 函数 func_get_args 返回一个包含函数参数列表的数组
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php function foo(){ $numargs = func_num_args(); echo "Number of arguments: $numargs<br />\n"; if ($numargs >= 2) { echo "Second argument is: " . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "Argument $i is: " . $arg_list[$i] . "<br />\n"; } } foo(1, 2, 3); ?>示例2
test.php<?php function foo() { include './fga.inc'; } foo('First arg', 'Second arg'); ?>fga.inc<?php$args = func_get_args(); var_export($args); ?>示例3
<?php function byVal($arg) { echo 'As passed : ', var_export(func_get_args()), PHP_EOL; $arg = 'baz'; echo 'After change : ', var_export(func_get_args()), PHP_EOL; } function byRef(&$arg) { echo 'As passed : ', var_export(func_get_args()), PHP_EOL; $arg = 'baz'; echo 'After change : ', var_export(func_get_args()), PHP_EOL; } $arg = 'bar'; byVal($arg); byRef($arg); ?>
- 函数处理 函数 register_shutdown_function 注册一个会在php中止时执行的函数
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php function shutdown(){ // This is our shutdown function, in // here we can do any last operations // before the script is complete. echo 'Script executed with success', PHP_EOL; } register_shutdown_function('shutdown'); ?>
- 函数处理 函数 register_tick_function Register a function for execution on each tick
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php declare(ticks=1); // using a function as the callbackregister_tick_function('my_function', true); // using an object->method$object = new my_class(); register_tick_function(array(&$object, 'my_method'), true); ?>
- 函数处理 函数 create_function Create an anonymous (lambda-style) function
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php $newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b); '); echo "New anonymous function: $newfunc\n"; echo $newfunc(2, M_E) . "\n"; // outputs// New anonymous function: lambda_1// ln(2) + ln(2.718281828459) = 1.6931471805599?>示例2
<?php function process($var1, $var2, $farr){ foreach ($farr as $f) { echo $f($var1, $var2) . "\n"; } } // create a bunch of math functions$f1 = 'if ($a >=0) { return "b*a^2 = ".$b*sqrt($a); } else { return false; } '; $f2 = "return \"min(b^2+a, a^2,b) = \".min(\$a*\$a+\$b,\$b*\$b+\$a); "; $f3 = 'if ($a > 0 && $b != 0) { return "ln(a)/b = ".log($a)/$b; } else { return false; } '; $farr = array( create_function('$x,$y', 'return "some trig: ".(sin($x) + $x*cos($y)); '), create_function('$x,$y', 'return "a hypotenuse: ".sqrt($x*$x + $y*$y); '), create_function('$a,$b', $f1), create_function('$a,$b', $f2), create_function('$a,$b', $f3) ); echo "\nUsing the first array of anonymous functions\n"; echo "parameters: 2.3445, M_PI\n"; process(2.3445, M_PI, $farr); // now make a bunch of string processing functions$garr = array( create_function('$b,$a', 'if (strncmp($a, $b, 3) == 0) return "** \"$a\" '. 'and \"$b\"\n** Look the same to me! (looking at the first 3 chars)"; '), create_function('$a,$b', '; return "CRCs: " . crc32($a) . ", ".crc32($b); '), create_function('$a,$b', '; return "similar(a,b) = " . similar_text($a, $b, &$p) . "($p%)"; ') ); echo "\nUsing the second array of anonymous functions\n"; process("Twas brilling and the slithy toves", "Twas the night", $garr); ?>示例3
<?php $av = array("the ", "a ", "that ", "this "); array_walk($av, create_function('&$v,$k', '$v = $v . "mango"; ')); print_r($av); ?>示例4
<?php $sv = array("small", "larger", "a big string", "it is a string thing"); print_r($sv); ?>示例5
<?php usort($sv, create_function('$a,$b','return strlen($b) - strlen($a); ')); print_r($sv); ?>
- 函数处理 函数 function_exists 如果给定的函数已经被定义就返回 true
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
示例1
<?php if (function_exists('imap_open')) { echo "IMAP functions are available.<br />\n"; } else { echo "IMAP functions are not available.<br />\n"; } ?>
- 函数处理 函数 unregister_tick_function De-register a function for execution on each tick
-
发表日期:2021-07-01 08:57:16 | 来源: | 分类:函数处理 函数
-
unregister_tick_function
(PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8)
unregister_tick_function — De-register a function for execution on each tick
说明
unregister_tick_function(string$function_name): voidDe-registers the function named by
function_nameso it is no longer executed when a tick is called.参数
-
function_name -
The function name, as a string.
返回值
没有返回值。
-
- 函数处理 函数 forward_static_call Call a static method
-
发表日期:2021-07-01 08:57:15 | 来源: | 分类:函数处理 函数
-
示例1
<?php class A{ const NAME = 'A'; public static function test() { $args = func_get_args(); echo static::NAME, " ".join(',', $args)." \n"; } } class B extends A{ const NAME = 'B'; public static function test() { echo self::NAME, "\n"; forward_static_call(array('A', 'test'), 'more', 'args'); forward_static_call( 'test', 'other', 'args'); } } B::test('foo'); function test() { $args = func_get_args(); echo "C ".join(',', $args)." \n"; } ?>
- 函数处理 函数 forward_static_call_array Call a static method and pass the arguments as array
-
发表日期:2021-07-01 08:57:15 | 来源: | 分类:函数处理 函数
-
示例1
<?php class A{ const NAME = 'A'; public static function test() { $args = func_get_args(); echo static::NAME, " ".join(',', $args)." \n"; } } class B extends A{ const NAME = 'B'; public static function test() { echo self::NAME, "\n"; forward_static_call_array(array('A', 'test'), array('more', 'args')); forward_static_call_array( 'test', array('other', 'args')); } } B::test('foo'); function test() { $args = func_get_args(); echo "C ".join(',', $args)." \n"; } ?>
- 函数处理 函数 call_user_func_array 调用回调函数,并把一个数组参数作为回调函数的参数
-
发表日期:2021-07-01 08:57:15 | 来源: | 分类:函数处理 函数
-
示例1
<?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 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")); ?>示例2
<?php namespace 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')); ?>示例3
<?php $func = function($arg1, $arg2) { return $arg1 * $arg2; } ; var_dump(call_user_func_array($func, array(2, 4))); /* As of PHP 5.3.0 */ ?>示例4
<?php function mega(&$a){ $a = 55; echo "function mega \$a=$a\n"; } $bar = 77; call_user_func_array('mega',array(&$bar)); echo "global \$bar=$bar\n"; ?>
- 函数处理 函数 func_get_arg 返回参数列表的某一项
-
发表日期:2021-07-01 08:57:15 | 来源: | 分类:函数处理 函数
-
示例1
<?php function foo(){ $numargs = func_num_args(); echo "Number of arguments: $numargs<br />\n"; if ($numargs >= 2) { echo "Second argument is: " . func_get_arg(1) . "<br />\n"; } } foo (1, 2, 3); ?>示例2
test.php<?php function foo() { include './fga.inc'; } foo('First arg', 'Second arg'); ?>fga.inc<?php$arg = func_get_arg(1); var_export($arg); ?>示例3
<?php function byVal($arg) { echo 'As passed : ', var_export(func_get_arg(0)), PHP_EOL; $arg = 'baz'; echo 'After change : ', var_export(func_get_arg(0)), PHP_EOL; } function byRef(&$arg) { echo 'As passed : ', var_export(func_get_arg(0)), PHP_EOL; $arg = 'baz'; echo 'After change : ', var_export(func_get_arg(0)), PHP_EOL; } $arg = 'bar'; byVal($arg); byRef($arg); ?>
- 类/对象 函数 trait_exists 检查指定的 trait 是否存在
-
发表日期:2021-07-01 08:57:12 | 来源: | 分类:类/对象 函数
-
trait_exists
(PHP 5 >= 5.4.0, PHP 7, PHP 8)
trait_exists — 检查指定的 trait 是否存在
说明
trait_exists(string$traitname, bool$autoload= ?): bool参数
-
traitname -
待检查的 trait 的名称
-
autoload -
如果尚未加载,是否使用自动加载(autoload)。
返回值
如果 trait 存在返回
true,不存在则返回false。发生错误的时候返回null。 -
- 类/对象 函数 method_exists 检查类的方法是否存在
-
发表日期:2021-07-01 08:57:12 | 来源: | 分类:类/对象 函数
-
示例1
<?php $directory = new Directory('.'); var_dump(method_exists($directory,'read')); ?>示例2
<?php var_dump(method_exists('Directory','read')); ?>
- 前端开发(1)
- 数据库(0)
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)
- JAVA(0)
- Android(0)
- Linux(0)
- AI大模型(9)
- 其他(0)
宁公网安备 64010402001209号