note 117036 added to functions.arguments
| From: | Anonymous | Date: | Mon, 06 Apr 2015 09:06:26 +0000 |
| Subject: | note 117036 added to functions.arguments | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202170@lists.php.net to get a copy of this message | ||
array() used as default value <notice>
<?php
function echoArray($myarr = array("firstname"
=>"dear","lastname"=>"girl"))
{
var_dump($myarr);
}
echoArray();
$myarr = array("lastname"=>"world");
echoArray($myarr);
$myarr2 = array("other"=>"nothing");
echoArray($myarr2);
?>
get this result:
array (size=2)
'firstname' => string 'dear' (length=4)
'lastname' => string 'girl' (length=4)
array (size=1)
'lastname' => string 'world' (length=5)
array (size=1)
'other' => string 'nothing' (length=7)
!important:
so before using the value,you had better call isset([key]) to make sure the key is existed
<?php
function pasteArray($arr = array("key"=>"value") , &$target)
{
$target[0] = isset(arr['key']) ? arr['key'] : "none";
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 27.17.29.173
----
Manual Page -- http://php.net/manual/en/functions.arguments.php
Edit -- https://master.php.net/note/edit/117036
Del: integrated -- https://master.php.net/note/delete/117036/integrated
Del: useless -- https://master.php.net/note/delete/117036/useless
Del: bad code -- https://master.php.net/note/delete/117036/bad+code
Del: spam -- https://master.php.net/note/delete/117036/spam
Del: non-english -- https://master.php.net/note/delete/117036/non-english
Del: in docs -- https://master.php.net/note/delete/117036/in+docs
Del: other reasons-- https://master.php.net/note/delete/117036
Reject -- https://master.php.net/note/reject/117036
Search -- https://master.php.net/manage/user-notes.php