note 96904 added to function.return
| From: | Radu at osu1 dot php dot net | Date: | Mon, 22 Mar 2010 11:17:28 +0000 |
| Subject: | note 96904 added to function.return | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167289@lists.php.net to get a copy of this message | ||
When returning an array, you should declare the array before the return, else the result is not as
you expect;
Watch this example:
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
----
Server IP: 69.147.83.197
Probable Submitter: 212.93.155.131
----
Manual Page -- http://www.php.net/manual/en/function.return.php
Edit -- https://master.php.net/note/edit/96904
Del: integrated -- https://master.php.net/note/delete/96904/integrated
Del: useless -- https://master.php.net/note/delete/96904/useless
Del: bad code -- https://master.php.net/note/delete/96904/bad+code
Del: spam -- https://master.php.net/note/delete/96904/spam
Del: non-english -- https://master.php.net/note/delete/96904/non-english
Del: in docs -- https://master.php.net/note/delete/96904/in+docs
Del: other reasons-- https://master.php.net/note/delete/96904
Reject -- https://master.php.net/note/reject/96904
Search -- https://master.php.net/manage/user-notes.php