Page 1 of 1

The "in" equivlence in PHP

Posted: Fri Oct 04, 2002 8:41 am
by PingLeeQuan
Good Mornin/Afternoon. I have a table that contains IDs. I am trying to validate the user input (many checkboxes on the screen) against these IDs.

Using SQL i can use the IN phrase to determin weather the input is IN the table. But this will require me to hit the table as many times as there are IDs.

I loaded the table IDs in an array and i am looping on the user input to determine existance of the IDs in the array. I have another loop that goes through the table array...... Not too good of a practice.

while ($i <= $UserInput_Count){
for ($j=0, $j<=$ID_Table_COUNT, $j++){
if ($UserInput == $ID_Table[j]){
$FOUND = true;
$i=9999;
break;
}
}
}

Instead of this, i am trying to employee something like the following method........ The question is does PHP have a similar control statment that allows me to acomplish it. (using the IN phrase)

if ($UserInput IN $ID_Table[j]){
......}


thanks

Posted: Fri Oct 04, 2002 8:44 am
by twigletmac
Have a look at PHP's array functions, specifically in_array().

Mac