Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, ]; 
like image 335
MikO Avatar asked Apr 22 '15 10:04

MikO


People also ask

What are associative arrays in PHP?

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:

How do you add an element to an associative array?

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);

How do I change the style of my code in PhpStorm?

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.

When should I use associative arrays?

Use an associative array when you want to reference elements by names rather than numbers. Did you find this tutorial useful?


1 Answers

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

enter image description here


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

enter image description here

like image 146
LazyOne Avatar answered Sep 28 '22 22:09

LazyOne