Phpstorm replace array () notation with [] short syntax

I would like to convert all the "array (...)" notations to "[...]" in my project, but I did not find a regex that works for all cases.

You have something that works for all cases (nested array, array on multiple lines, nested array on multiple lines)

Thank.

+43
regex replace phpstorm
May 16 '14 at 14:04
source share
3 answers
  • Code | Inspect Code... Code | Inspect Code... --- run it in your files. One of the checks, called "Traditional syntax array, literal detected . "

    Alternatively, just run this special inspection only through Code | Run Inspection by Name... Code | Run Inspection by Name...

  • After that, you will see a list with the results. Find this particular check in the results (if using the 1st option (all checks)).

  • From there, you can apply the Fix action on all (or individual) results of this check.

PS This check / fix is ​​available with PhpStorm v7.1.

enter image description here

+101
May 16 '14 at 14:59
source share

Open file-> Settings ... Click "Editor" → "Code Style" → PHP Open the "Other" tab. Now you can find the "Array Ad Style" block. If you check the "Force short ad style" checkbox, your "array (...)" becomes "[...]" when you run the Reformat code (Ctrl + Shift + L).

+11
Mar 19 '17 at 13:15
source share

At the moment (PHPStorm 2017.3.2) it is here: Settings/Editor/Code Style/PHP/Code Conversion/Array Declaration style

enter image description here

0
Dec 29 '17 at 12:39 on
source share



All Articles