Home >Development Tools >phpstorm >Align key-value pairs of arrays using PHPStorm

Align key-value pairs of arrays using PHPStorm

步履不停
步履不停Original
2019-06-26 17:41:145457browse

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:

Align key-value pairs of arrays using PHPStorm

In addition, it is recommended to check these two items in Code Conversion:

Align key-value pairs of arrays using PHPStorm

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn