# PHP - if value is in array



## amanxman (Mar 28, 2006)

Hey,

in PHP:

I have a SQL statement:


```
$contactquery = sprintf("SELECT * FROM cms_contacts WHERE num = '$currentnum'");

$result = mysql_query($contactquery);

while ($row = mysql_fetch_assoc($result)) {
$checkedproperties = $row['properties'];
}
```
The 'while' is used to create the $checkproperties variable, which results e.g. 57 58 (i.e. numbers)

If now want an IF statement which says IF $variable is within the above result ($result / $contactquery)...

So, for example, the $result is outputting 57, 58

And I want an IF statement, IF $variable = 57 or 58, then...

I have:

```
if ($variable == $checkedproperties')
```
But that doesn't work since $checkedproperties is multi value (57 and 58).

And I can't just do a LIKE/WILDCARD because it'll pull results like 157 being the same as 57.

Hence, the IF $variable is in the $result...

I hope this makes sense!
Cheers in advance
Cheers


----------



## amanxman (Mar 28, 2006)

UPDATE:

Found in_array function:


```
$os = (57, 58);
if (in_array($row['num'], $os)) {
   echo "blaa";
}
```
However, I now need to return an array in format 57, 58 etc from the above. $checkedproperties outputs 57 58 (without the comma), and str_replace on space, replace with comma doesn't wory.

How can I get an array out of $checkproperties or $result?

Cheers


----------

