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) ?> Quote Link to comment 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 (,). Quote Link to comment 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) ?> Quote Link to comment 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. Quote Link to comment 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.