这是一个php bug [关闭]

why this code has error (Notice: Use of undefined constant ‍‍ - assumed '‍‍' on line 5)

<?
$arr1 = array(
">",
"<",‍‍
);

foreach ($arr1 as $value) {
echo $value;
}

This is not a bug. You have "non printable chars" in your code at that specific lines, that's why you get a notice. See image, vi never lies! :P

enter image description here

Delete your code and rewrite it from scratch (no copy/paste) and it will work

I think the error is the comma in your Array. Try this:

<?
$arr1 = array(
">",
"<"
);

foreach ($arr1 as $value) {
echo $value;
}

Depending on your version of PHP, your code is valid. Unfortunately for you, your version does not support trailing commas, so you will just need to remove it like so:

<?
$arr1 = array(
    ">",
    "<"
);

foreach ($arr1 as $value) {
    echo $value;
}

Read this in the documentation:

“Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.”

<?php
    $my_array = array('foo', 'bar', 'bat',);
?>

But, depending on the version of PHP you are using, it might be invalid. It is better to remove the trailing commas, if the array is static and can be changed, by hand, and not those kind which are generated by eval() and other codes.

So, the code for you would be:

<?
$arr1 = array(
    ">",
    "<" // Removing the trailing comma.
);

foreach ($arr1 as $value) {
    echo $value;
}

But something which strikes me is, what is the version of PHP you are using? Coz, all the decent versions (PHP 5, 6) have a tolerance to one trailing comma.

And also, you must check for UTF-8 BOM characters in your code. I generally use CuteFTP's editor to check them, or even a Hex Editor does the job well. When I copied your code and pasted it, I saw two characters here, see the screenshot:

And that's what was causing the problem. Remove them and your code is good.

The error is that there are two invisible characters (called zero width joiner character, hex E2 80 8D) after the last comma in the array.

Copy and paste the code from your example into a text editor, put your cursor in-front of the last comma, and then hit the left arrow key a few times. The cursor should stand still.

I am not quite sure why this has happened, but fixing it should be as simple as removing them:

$arr1 = array('>', '<');

@Pushpesh i think there is no issue with using , at the end of array look at this http://codepad.org/oUj8PwY2