Jump to content

One of these (.php array) things is not like the other... but why?


Mavent

Recommended Posts

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",);
?>

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.