note 96904 deleted from function.return by googleguy
| From: | googleguy@php.net | Date: | Thu, 02 Jan 2014 23:15:03 +0000 |
| Subject: | note 96904 deleted from function.return by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198085@lists.php.net to get a copy of this message | ||
Note Submitter: Radu
----
When returning an array, you should declare the array before the return, else the result is not as
you expect;
Watch this example:
<?php
function a(){
return $a['e'] = 'sometxt';
}
function b(){
$a['e'] = 'sometxt';
return $a;
}
function c(){
if(is_array(a())){
echo 'a is array';
}else{
echo 'a is NOT an array';
}
if(is_array(b())){
echo 'b is array';
}else{
echo 'b is NOT an array';
}
}
?>
This will print:
a is NOT an array
b is array