Why do PHP Array Examples Leave a Trailing Comma?

后端 未结 10 1592

I have seen examples like the following:

$data = array(
   \'username\' => $user->getUsername(),
   \'userpass\' => $user->getPassword(),
   \'em         


        
10条回答
  •  萌比男神i
    2020-12-05 09:38

    I've always added commas at the start of the new entry. Compilers see it as the single-character token of look-ahead that says "there is another one coming". I don't know if modern compilers use LR(1) (left-recursive, single token look-ahead) but I think that's where the syntax error originates when an a comma has nothing after it. It is rare that I've ever had another developer agree with me, but it looks like JohnBrooking does!

提交回复
热议问题