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
JKM
Forum Contributor
Posts: 221 Joined: Tue Jun 17, 2008 8:12 pm
Post
by JKM » Sun Jun 21, 2009 5:51 am
Hi there!
I am using a $piece = explode('.', $something); and I was wondering about how I make a loop that makes it unnecessary to do like this:
Code: Select all
if($piece[0] == $_POST['something'] || $piece[1] == $_POST['something'] || $piece[3] == $_POST['something']) {
// something
}.. When I don't know how many pieces I can end up with.
ambivalent
Forum Contributor
Posts: 173 Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON
Post
by ambivalent » Sun Jun 21, 2009 6:10 am
JKM
Forum Contributor
Posts: 221 Joined: Tue Jun 17, 2008 8:12 pm
Post
by JKM » Sun Jun 21, 2009 6:47 am
Hmm, do I have to use a loop inside the loop (yo dawg!)?
The result I want, is like this: if($_POST['something'] isin explode('.', $fetch['something']) { //something }
But I'm quite blank, sorry.
ambivalent
Forum Contributor
Posts: 173 Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON
Post
by ambivalent » Sun Jun 21, 2009 10:26 am
Code: Select all
$pieces = array('one', 'two', 'three');
foreach ($pieces as $piece)
{
if ($piece == 'two')
{
echo $piece;
}
}
//output == two