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
DynamiteHost
Forum Commoner
Posts: 69 Joined: Sat Aug 10, 2002 5:33 pm
Post
by DynamiteHost » Sat Nov 02, 2002 8:18 am
Hi,
Say I had $var and it was holding "1,2,3,4,5,6" ....
How would I get it to split or explode the numbers?
Thanks
DynamiteHost
Forum Commoner
Posts: 69 Joined: Sat Aug 10, 2002 5:33 pm
Post
by DynamiteHost » Sat Nov 02, 2002 9:08 am
how would i be able to use the variables which have been made?
would it be $arr[0], $arr[1] etc or what?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Nov 02, 2002 9:11 am
exactly
e.g.
Code: Select all
for($i=0; $i!=count($arr); $i++)
echo $arrї$i], '<br/>';
foreach ($arr as $value)
echo $value, '<br/>';
foreach ($arr as $key=>$value)
echo $key, '=>', $value, '<br/>';
DynamiteHost
Forum Commoner
Posts: 69 Joined: Sat Aug 10, 2002 5:33 pm
Post
by DynamiteHost » Sat Nov 02, 2002 12:09 pm
hmm.. I don't think this is what I need... sorry
how would I be able to see if $var contained something equal to $product ?
Thanks
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Nov 02, 2002 3:57 pm
what is $product?
DynamiteHost
Forum Commoner
Posts: 69 Joined: Sat Aug 10, 2002 5:33 pm
Post
by DynamiteHost » Sat Nov 02, 2002 4:38 pm
$product would be one of the numbers in $var
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Nov 02, 2002 5:49 pm
e.g.
Code: Select all
$var = '1,2,3,4,5';
$product = 3;
$arr = explode(',', $var);
if (in_array($product, $arr)
{
echo 'in array<br/>';
$index = array_search($product, $var);
echo $index;
}http://www.php.net/manual/en/function.in-array.php
http://www.php.net/manual/en/function.array-search.php