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

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

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