NYCPHP Meetup

NYPHP.org

[nycphp-talk] Question Using If's and Possible Arrays

IAlsoAgree at stny.rr.com IAlsoAgree at stny.rr.com
Tue Jan 17 20:48:04 EST 2006


Meh... me and lazyness. Actually I've been working on my first big
project with PHP and I'm still caught up in the functions I'm writing.

For anyone who is interested, I tested the following code:
 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 returned (as expected):
As true statement returns false.

As true statement returns true.

Statment returned as false.

Statement returned as false.

-Joe

----- Original Message -----
From: Daniel Convissor <danielc at analysisandsolutions.com>
Date: Tuesday, January 17, 2006 8:36 pm
Subject: Re: [nycphp-talk] Question Using If's and Possible Arrays

> Joe:
> 
> On Tue, Jan 17, 2006 at 08:20:03PM -0500, IAlsoAgree at stny.rr.com 
> wrote:> function callfunction()
> >  {
> >   return false;
> >  }
> >
> > $variable = callfunction()
> > 
> > if ($variable['alias'])
> 
> You made a nearly perfect test case.  Why don't you run it and see 
> what 
> happens?  You'd have your answer already.
> 
> --Dan
> 
> PS:  You'll find that you need to check for "if ($variable)" first.
> 
> -- 
> T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
>            data intensive web and database programming
>                http://www.AnalysisAndSolutions.com/
> 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409
> _______________________________________________
> New York PHP Community Talk Mailing List
> Show Your Participation
> http://www.nyphp.org/show_participation.php
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
> 



More information about the talk mailing list