jarv Posted November 23, 2009 Share Posted November 23, 2009 Parse error: syntax error, unexpected '[', expecting ')' in /Users/admin/Sites/phptest/array.php on line 5 <?php function shippingPrice($zone,$weight){ $ground = array(2 => array ( array(['lower'] => 0,['higher'] => 70,['av'] => 0.147,['base'] => 4.85); array(['lower'] => 70,['higher'] => 100,['av'] => 0.710,['base'] => 14.82); array(['lower'] => 100,['higher'] => 150,['av'] => 0.544,['base'] => 38.20); ) ) foreach ($ground[$zone] as $row) { if($row['lower'] <= $weight and $row['higher'] => $weight){ $price = (($weight - $row['base'])*$row['av']+$row['base']) break; } echo shippingPrice(2,62) ?> Link to comment https://forums.phpfreaks.com/topic/182626-parse-error/ Share on other sites More sharing options...
cags Posted November 23, 2009 Share Posted November 23, 2009 Get rid of all the square braces ([ and ]) in the $ground array. Replace the 3 semicolons ( with commas (,). Link to comment https://forums.phpfreaks.com/topic/182626-parse-error/#findComment-963895 Share on other sites More sharing options...
jarv Posted November 23, 2009 Author Share Posted November 23, 2009 thanks, now I get: Parse error: syntax error, unexpected T_FOREACH in /Users/admin/Sites/phptest/array.php on line 11 <?php function shippingPrice($zone,$weight){ $ground = array(2 => array ( array('lower' => 0,'higher' => 70,'av' => 0.147,'base' => 4.85), array('lower' => 70,'higher' => 100,'av' => 0.710,'base' => 14.82), array('lower' => 100,'higher' => 150,'av' => 0.544,'base' => 38.20), ) ) foreach($ground[$zone] as $row) { if($row['lower'] <= $weight and $row['higher'] => $weight){ $price = (($weight - $row['base'])*$row['av']+$row['base']) break; } echo shippingPrice(2,62) ?> Link to comment https://forums.phpfreaks.com/topic/182626-parse-error/#findComment-963912 Share on other sites More sharing options...
cags Posted November 23, 2009 Share Posted November 23, 2009 The closing bracket above foreach needs a semicolon after it. This will tell PHP that you have finished the line of code which creates $ground. Link to comment https://forums.phpfreaks.com/topic/182626-parse-error/#findComment-963917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.