Home >Development Tools >phpstorm >Align key-value pairs of arrays using PHPStorm
When defining an array in PHPStorm, it is often written as follows:
public function index() { return [ 'foo' => 'bar', 'foo-bar' => 'foo-bar', 'f' => 'b' ]; }
At this time, a group of obsessive-compulsive disorders jumped out and said why the key values of this group are not aligned. , why there is no trailing comma, too ugly to read. . At this time, changing some settings in PHPStorm can achieve the following effect:
public function index() { return [ 'foo' => 'bar', 'foo-bar' => 'foo-bar', 'f' => 'b', ]; }
Setting steps
OpenSettings - > Editor -> PHP -> Warpping and Braces
, find Array itializer -> Align key-value paipars
and check and save, then use Ctrl Alt L
When formatting the code, the key-value pairs of the array will be automatically aligned:
In addition, it is recommended to check these two items in Code Conversion
:
When formatting, these two items will force the use of array short syntax, and the last element will automatically be followed by a comma.
PS: Note that the location of the above configuration items may be different in lower versions of PHPStorm. You can directly enter the name of the configuration item in the search box to locate it.
Recommended related PHP video tutorials: "PHP Video Tutorial"
The above is the detailed content of Align key-value pairs of arrays using PHPStorm. For more information, please follow other related articles on the PHP Chinese website!