Page 1 of 1

PHP loop function help needed!

Posted: Mon Apr 16, 2007 1:32 pm
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

Posted: Mon Apr 16, 2007 1:36 pm
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 )
?>

Posted: Mon Apr 16, 2007 4:41 pm
by feyd
You don't need the reference here either.

Posted: Tue Apr 17, 2007 6:50 am
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.