<?php $haystack=array('12345 ','23456','34567','45678'); $needle='12345'; $result=false; foreach($haystack as $val){ if(trim($val)==$needle){ $result=true; break; } }; var_dump($result);