PHP loop function help needed!

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
oskare100
Forum Commoner
Posts: 80
Joined: Sun Oct 29, 2006 5:47 am

PHP loop function help needed!

Post by oskare100 »

Hello,
I'm trying to get this code to work:

Code: Select all

$item_number="5161516161,784684664864684";

$item_numbers = explode(",", $item_number);
foreach ($item_numbers as &$item_number) {
echo "$item_number";
)
I need it to split the 5161516161,784684664864684 and run " echo "$item_number"; " twice, one for each item number.

So if $item_number="5161516161,784684664864684,15515151"; then the script is supposed to run " echo "$item_number"; " three times, one time for each item number.

Please help, how can I do that? What is wrong with my code/how should it be?

/Oskar
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The only thing wrong with it at the moment is the syntax of your code. You have a closing paren where there should be a brace.

Code: Select all

<?php
$item_number="5161516161,784684664864684";

$item_numbers = explode(",", $item_number);
foreach ($item_numbers as &$item_number) {
    echo $item_number;
} // In your code this was a )
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You don't need the reference here either.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Develop with reporting set high enough like

Code: Select all

error_reporting(E_ALL | E_STRICT)
and display_errors on

Code: Select all

ini_set('display_errors', true);
set display_errors to false when in production.
Post Reply