Page 1 of 1

Can you not use stristr on arrays??

Posted: Tue Apr 20, 2004 7:38 am
by MetalElmo
Can you not use stristr or strstr on arrays? or am i doing something wrong?

Code: Select all

$stuff = array('Hello', 'Hacker', 'Cracker', 'Goat', 'Movie', 'Girl', 'Sad');
      $is = stristr($stuff, 'S');
      echo $is;
From my understanding it should output Sad, am I wrong?

Posted: Tue Apr 20, 2004 7:51 am
by magicrobotmonkey
try

Code: Select all

<?php
 $is = stristr($stuff[6], 'S');

?>

Not possible

Posted: Tue Apr 20, 2004 7:52 am
by Lord Sauron
Hi there,

strstr and stristr are string functions. They cannot be used for arrays, only on the individual parameters of the array. So you have to 'explode' the array first, than perform stristr($array[$i],'s') to all parameters by means of a for-loop.

Kind regards,

Antonie

Posted: Tue Apr 20, 2004 7:55 am
by MetalElmo
Blah.
Ok, thanks guys

Posted: Tue Apr 20, 2004 8:00 am
by redmonkey