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, ];
Summary: in this tutorial, you will learn about PHP associative arrays and how to use them effectively. Associative arrays are arrays that allow you to keep track of elements by names rather than by numbers. To create an associative array, you use the array () construct: or the JSON notation syntax:
Adding elements to an associative array To add an element to an associative array, you need to specify a key. For example, the following adds the title to the $html array: <?php $html ['title'] = 'PHP Associative Arrays'; $html ['description'] = 'Learn how to use associative arrays in PHP'; print_r ($html);
Reformat your code ( Ctrl+Alt+L ). PhpStorm will reformat your code in accordance with the current style settings, keeping existing formatting for the rules which you've selected. You can rearrange your code according to the arrangement rules set in the Code Style. PHP page of the Settings/Preferences dialog.
Use an associative array when you want to reference elements by names rather than numbers. Did you find this tutorial useful?
Settings (Preferences on Mac) | Editor | Code Style | PHP | Other | Array declaration style -> Align key-value pairs
Since PhpStorm 2017.x version it is now located at Settings (Preferences on Mac) | Editor | Code Style | PHP | Wrapping and Braces --> Array initializer | Align key-value pairs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With