-1

Why doesn't this work?

$statement = array(
   images_name[0] => 'small_01.jpg', 
   images_name[1] => 'large_01.jpg', 
);

foreach ($statement->images as $image): 
if (strpos($image->name, 'small')) { 
    echo ('yes');
}
endforeach

I can print the image name without problem but strpos is not working.

softvar
  • 16,589
  • 10
  • 48
  • 74
  • Welcome to Stack Overflow! Please explain what you mean by "not working". Please include **full** tracebacks (if they exist) and expected results. – Veedrac Jun 08 '14 at 21:20

2 Answers2

0

A strpos work, but it returning 0 - position of your word in filename.
Better solution:

strstr($image->name, 'small') !== false

Strstr function will return false when string not found or position when found.

aso
  • 1,175
  • 4
  • 13
  • 27
  • If I helped you, please mark this reply as "best answer". You will also receive reputation (+2). – aso Jun 08 '14 at 23:50
0

You must use:

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

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

Also, if you want to know why you need the use of "!==" or "===" read this: How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?

Community
  • 1
  • 1
Fantini
  • 1,819
  • 18
  • 29