array_keys

What’s wrong with this syntax?


echo array_keys($_SESSION['tablearray'])[0];

Trying to access array values directly from a function call, as you are trying to do, is currently* not allowed. You either need to use some other way to get at the information that you want.


// preferred
$keys = array_keys($_SESSION['tablearray']);
echo $keys[0];
// alternative (both of the following assume you want to get the first key)
echo current(array_keys($_SESSION['tablearray']));
// or
reset($_SESSION['tablearray']);
echo key($_SESSION['tablearray']);

  • For what it’s worth, PHP 5.4.0 will introduce the syntax that you are trying to use under the name “function array dereferencing”.