note 96904 modified in function.return by thiago
| From: | thiago@php.net | Date: | Mon, 22 Mar 2010 14:29:53 +0000 |
| Subject: | note 96904 modified in function.return by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167294@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:
<?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
--was--
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
http://php.net/manual/en/function.return.php