PHP foreach and strpos newbie -


why doesn't work?

$statement = array(    images_name[0] => 'small_01.jpg',     images_name[1] => 'large_01.jpg',  );  foreach ($statement->images $image):  if (strpos($image->name, 'small')) {      echo ('yes'); } endforeach 

i can print image name without problem strpos not working.

you must use:

foreach ($statement->images $image)   if ( strpos($image->name, 'small') !== false ) {      echo ('yes');   } 

explained here: http://us3.php.net//manual/en/function.strpos.php

also, if want know why need use of "!==" or "===" read this: how php equality (== double equals) , identity (=== triple equals) comparison operators differ?


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -