NYCPHP Meetup

NYPHP.org

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

Kenneth Downs ken at secdat.com
Tue Jan 17 21:01:44 EST 2006


PHP has a construct for this:

if ( ($variable=callfunction()) === false) {
  .. nothing happens
}
else {
   ....processing here...
}

the triple equals sign means "matches on type and value". So you can
distinguish between these two kinds of cases:

if (0==false)  { echo "this code will execute"; }
if (0===false) { echo "this code will not execute"; }

> I have a question about using if statements with variables that are
> sometimes arrays and sometimes not arrays.
>
> I have a function that returns either the contents of a database row or
> false.
> For example:
> $variable = callfunction()
>
> In this case, callfunction would either return the contents of a row in
> a database or simply false.
>
> Lets assume that, for instances of this question, callfunction returns
> false and $variable is now equal to false.
> function callfunction()
>  {
>   return false;
>  }
>
> If I then use:
> if ($variable['alias'])
>
> Will the if statement result in false because that is the only value of
> $variable (noting that $variable has NOT been initiated as an array,
> this is the first time it has been refrenced as an array)?
>
> -Joe
>
>
> _______________________________________________
> 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
>


-- 
Kenneth Downs
Secure Data Software
631-379-0010
ken at secdat.com
PO Box 708
East Setauket, NY 11733




More information about the talk mailing list