note 118283 added to functions.arguments
| From: | ohcc at 163 dot com | Date: | Sun, 08 Nov 2015 09:23:53 +0000 |
| Subject: | note 118283 added to functions.arguments | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204110@lists.php.net to get a copy of this message | ||
As of PHP 5.6, you can use an array as arguments when calling a function with the ... $args syntax.
<?php
$args = array('wu','WU','wuxiancheng.cn');
$string = str_replace(...$args);
echo $string;
?>
Ha ha, is that interesting and powerful?
Also you can use it like this
<?php
$args = array('WU','wuxiancheng.cn');
$string = str_replace('wu', ...$args);
echo $string;
?>
It also can be used to define a user function.
<?php
function wxc ($arg1, $arg2, ...$otherArgs){
echo '<pre>';
print_r($otherArgs);
print_r(func_get_args());
echo '</pre>';
}
wxc (1, 2, ...array(3,4,5));
?>
REMEMBER this: ... $args is not supported in PHP 5.5 and older versions.
----
Server IP: 72.52.91.14
Probable Submitter: 118.124.214.5
----
Manual Page -- http://php.net/manual/en/functions.arguments.php
Edit -- https://master.php.net/note/edit/118283
Del: integrated -- https://master.php.net/note/delete/118283/integrated
Del: useless -- https://master.php.net/note/delete/118283/useless
Del: bad code -- https://master.php.net/note/delete/118283/bad+code
Del: spam -- https://master.php.net/note/delete/118283/spam
Del: non-english -- https://master.php.net/note/delete/118283/non-english
Del: in docs -- https://master.php.net/note/delete/118283/in+docs
Del: other reasons-- https://master.php.net/note/delete/118283
Reject -- https://master.php.net/note/reject/118283
Search -- https://master.php.net/manage/user-notes.php