Can you not use stristr on arrays??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MetalElmo
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2004 5:17 pm

Can you not use stristr on arrays??

Post 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?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

try

Code: Select all

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

?>
User avatar
Lord Sauron
Forum Commoner
Posts: 85
Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL

Not possible

Post 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
MetalElmo
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2004 5:17 pm

Post by MetalElmo »

Blah.
Ok, thanks guys
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Post Reply