Search code examples
phpsyntax-errorinvisible

Why do I get a syntax error with a PHP array definition that has no visible syntax errors?


Can anyone tell me what is wrong with this code block below?

The PHP compiler says:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /Users/mrunkel/Dropbox/Documents/New Store/Data Migration/utils/test.php on line 3 (sorry, I couldn't format this correctly, line 3 is the line that starts with "0050")

$data = array (
          "0010" => array ("1 to 10", 1, 10),

          "0050" => array("11 to 50", 11, 50),

          "0150" => array("51 to 150", 51, 150),

          "0500" => array("151 to 500", 151, 500),

          "1500" => array("501 to 1500", 501, 1500),

          "3000" => array("1501+", 1501, "")
);

This looks like an example straight out of PHP manual page for multi-dimensional arrays. I've tried adjusting the keys to integers, I've tried adjusting the values to integers or all strings, I keep getting the same error.

I've copied the exact offending code block directly from my environment into the question.


Solution

  • After each comma, you have a Unicode character U+8232 which is invisible here, but I can see them after I copy/pasted your code into my editor. Remove those and you'll be fine.