The "in" equivlence in PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
PingLeeQuan
Forum Commoner
Posts: 58
Joined: Tue Sep 03, 2002 8:08 am

The "in" equivlence in PHP

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have a look at PHP's array functions, specifically in_array().

Mac
Post Reply