3raser Posted June 24, 2010 Share Posted June 24, 2010 Keep getting a parse error? Parse error: parse error in C:\wamp\www\learning\loops.php on line 12 <?php $array; $array[0] = "1"; $array[1] = "7"; $array[2] = "3"; $array[3] = "4"; $array[4] = "3"; $variable = "3"; foreach($array as => $variable) { $number = 1 + $number; echo $number; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/205756-foreach/ Share on other sites More sharing options...
Daniel0 Posted June 24, 2010 Share Posted June 24, 2010 You need to either provide a variable name for the key or omit the => operator in the foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/205756-foreach/#findComment-1076707 Share on other sites More sharing options...
aeroswat Posted June 24, 2010 Share Posted June 24, 2010 Keep getting a parse error? Parse error: parse error in C:\wamp\www\learning\loops.php on line 12 <?php $array; $array[0] = "1"; $array[1] = "7"; $array[2] = "3"; $array[3] = "4"; $array[4] = "3"; $variable = "3"; foreach($array as => $variable) { $number = 1 + $number; echo $number; } ?> and what is $variable? I think you meant to put $number there Quote Link to comment https://forums.phpfreaks.com/topic/205756-foreach/#findComment-1076708 Share on other sites More sharing options...
thewooleymammoth Posted June 24, 2010 Share Posted June 24, 2010 <?php //... foreach($array as $key => $variable) //... //or foreach($array as $variable) ?> Quote Link to comment https://forums.phpfreaks.com/topic/205756-foreach/#findComment-1076777 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.