note 117036 deleted from functions.arguments by tularis
| From: | tularis@php.net | Date: | Mon, 06 Apr 2015 10:03:46 +0000 |
| Subject: | note 117036 deleted from functions.arguments by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-202173@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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";
}
?>