Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Tips for golfing in PHP

What general tips do you have for golfing in PHP? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to PHP (e.g. "remove comments" is not an answer). Please post one tip per answer.

Answer*

Cancel
3
  • 2
    \$\begingroup\$ Indeed, frequently a good replacement, though not exactly the same: pastebin.com/seYeaP38 \$\endgroup\$ Commented Jan 5, 2017 at 19:46
  • \$\begingroup\$ Ah yeah, dang it, I originally had the title "associative arrays ... " and then removed it. I'll clarify, thanks. \$\endgroup\$ Commented Jan 5, 2017 at 19:56
  • \$\begingroup\$ numeric arrays can also merged using +, as long as the indexes are distinct. If they are not, the values from the first array will be overwritten with those from the second one (just like array_merge). The difference: + does not reorder indexes. \$\endgroup\$ Commented Jan 6, 2017 at 0:11