Search code examples
phpphpstorm

How to make PhpStorm suggest / autocomplete array keys


<?php


function test(){
    return array(
        'one' => 1,
        'two' => 2
    );
}

$test = test();

echo $test[''];

I would like to put my cursor in the last line in between the single quotes, and have it suggest one or two. How can I do this?

The below works fine, so why doesn't it work inside of a function:

    $test = array(
        'one' => 1,
        'two' => 2
    );



    echo $test[''];
// Suggests 'one' and 'two'

Solution

  • The below works fine, so why doesn't it work inside of a function:

    Because it's implemented only for variables/class properties.

    How can I do this?

    Just install deep-assoc-completion plugin. It can do even more than that (e.g. help with completion of array parameter -- what keys are possible (if you bother to describe those keys, of course) etc).