note 60832 added to function.return
| From: | If | Date: | Wed, 18 Jan 2006 01:54:53 +0000 |
| Subject: | note 60832 added to function.return | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101999@lists.php.net to get a copy of this message | ||
I was working with functions that either returned arrays or simply false.
I wanted to make sure I could test the returned value as an array within an if statement and still
get it to return the appropriate response if the returned value wasn't an array.
This is a script I wrote to test it out:
<?php
function returnfalse()
{
return false;
}
function returntrue()
{
return true;
}
$i = returntrue();
if ($i['private'])
{
echo ("<p>As true statement returns true.</p>");
}
else
{
echo ("<p>As true statement returns false.</p>");
}
if ($i)
{
echo ("<p>As true statement returns true.</p>");
}
else
{
echo ("<p>As true statement returns false.</p>");
}
$i = returnfalse();
if ($i['private'])
{
echo ("<p>Statment returned as true.</p>");
}
else
{
echo ("<p>Statment returned as false.</p>");
}
if ($i)
{
echo ("<p>Statement returned as true.</p>");
}
else
{
echo ("<p>Statement returned as false.</p>");
}
?>
The script gives the following output:
As true statement returns false.
As true statement returns true.
Statment returned as false.
Statement returned as false.
----
Server IP: 64.71.164.2Probable Submitter: 69.205.246.167
----
Manual Page -- http://www.php.net/manual/en/function.return.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60832
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60832&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60832&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60832&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60832&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60832&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60832&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60832&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60832&report=yes
Search -- http://master.php.net/manage/user-notes.php