NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help!!

JeeBak Kim jbkim at cs.pdx.edu
Wed May 29 15:47:16 EDT 2002


* jose sanchez (j_r_sanchez at yahoo.com) [020529 12:21]:
> Hi All:
> 
> I am having a little problem:
[snip]
> function checkId( $id )
> {
>   global $text;
> 
>    for($i=1; $i<5; $i++ )
>    {
>     if( $text[$i]==$id )
>      print( 'Compared...' );
>      return true;
>    }
>    return false;
> 
> }
> 
> Some how the print statement in the checkId() never
> gets executed. I don't know why. What am I doing
> wrong?

Hmm... did you mean to have the the 'return true' within
the if test?  Basically, it's only doing one iteration of
the for loop and returning true.  Something like:

function checkId( $id )
{
  global $text;

   for($i=1; $i<5; $i++ )
   {
     if( $text[$i]==$id ) {     // missing brace
       print( 'Compared...' );
       return true;
     }                          // missing brace
   }
   return false;
}

This is the main reason I ALWAYS use {...} for if()'s, etc.
even if there is only one statement ;).

Don't know if this is what's causing your problem but it's
something that seemed contrary to intent.  Hope, this helps.

-- jbkim



More information about the talk mailing list