Search code examples
coding-stylephpstorm

Stop PhpStorm from aligning associative arrays


How can I tell PhpStorm (using version 8.0.3) to keep the following array as is when clicking Cmd+Alt+L to reformat my code:

$array = [
    'short' => 1, // I want this...
    'veryVeryVeryIncrediblyLong' => 123456789,
];

Instead of doing this:

$array = [
    'short'                      => 1, // Not this...
    'veryVeryVeryIncrediblyLong' => 123456789,
];

Solution

  • Since PhpStorm 2017.x version the appropriate option is located at:

    • Settings (Preferences on Mac) | Editor | Code Style
    • PHP | Wrapping and Braces
    • Array initializer | Align key-value pairs

    enter image description here


    ORIGINAL ANSWER (for v2016 and older)

    • Settings (Preferences on Mac) | Editor | Code Style | PHP
    • Other | Array declaration style -> Align key-value pairs

    enter image description here