48

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,
];
1
  • 1) And by "aligned" you mean multiple lines aligned by => characters? (better post aligned version as well, to be 100% clear). 2) Always state your PhpStorm version. Commented Apr 22, 2015 at 10:50

5 Answers 5

108

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

Sign up to request clarification or add additional context in comments.

1 Comment

I just created an issue on this see: youtrack.jetbrains.com/issue/WI-30571 . Align key-value pairs does not work on 10.0.3
55

In Phpstorm 2017.3 & later , This setting is located at File | Settings | Editor | Code Style | PHP | Wrapping and Braces | Array initializer | Align key-value pairs

enter image description here

Comments

19

Preferences → Editor → Code Style → PHP → Other → Align key-value pairs

enter image description here

Comments

3

PhpStorm 2019 and up: Settings -> editor -> PHP -> Wrapping and Braces -> Array initializer -> Align key-value pairs [*] (Linux OS)

PhpStorm 2019 and up

Comments

2

In phpstorm 2019 it goes somewhere like this: (settings > editor > php > Wrapping and Braces > Assignment statement > Align consecutive assignments) PHPStorm 9 align assignments in PHP

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.