Mavent Posted May 22, 2012 Share Posted May 22, 2012 In the following code, line 2 fails, but line 3 succeeds. Can anyone tell me why? the error line 2 throws is: Parse error: syntax error, unexpected T_STRING, expecting ')' <?php $test = array("foo" => "test","bar" => "test",); $array = array("foo" => "bar","bar" => "foo",); ?> Quote Link to comment https://forums.phpfreaks.com/topic/262955-one-of-these-php-array-things-is-not-like-the-other-but-why/ Share on other sites More sharing options...
rythemton Posted May 22, 2012 Share Posted May 22, 2012 <?php $test = array("foo" => "test","bar" => "test",); $array = array("foo" => "bar","bar" => "foo",); ?> The problem is the trailing comma (,) in your arrays. The second one is not actually succeeding, but once PHP throws a T_STRING error, it will stop running, so it won't find the second 'til the first is fixed. Quote Link to comment https://forums.phpfreaks.com/topic/262955-one-of-these-php-array-things-is-not-like-the-other-but-why/#findComment-1347801 Share on other sites More sharing options...
Kays Posted May 22, 2012 Share Posted May 22, 2012 I have never had issues with trailing commas in PHP in that scenario. Quote Link to comment https://forums.phpfreaks.com/topic/262955-one-of-these-php-array-things-is-not-like-the-other-but-why/#findComment-1347802 Share on other sites More sharing options...
.josh Posted May 22, 2012 Share Posted May 22, 2012 There is nothing wrong with the code you posted, your error is elsewhere. Or else the code you posted differs from the code you're running. Quote Link to comment https://forums.phpfreaks.com/topic/262955-one-of-these-php-array-things-is-not-like-the-other-but-why/#findComment-1347826 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.