r/PHPhelp • • Jul 26 '11

array question

New to php

function ReturnsArrayNotEmpty()...

Why can't I reference elements in the array like the following:

$value = $this->ReturnsArrayNotEmpty()[0];

?

Whereas, this works fine,

$value = $this->ReturnsArrayNotEmpty(); $another = $value[0];

8 Upvotes

3 comments sorted by

View all comments

9

u/NedRyerson Jul 26 '11 edited Jul 26 '11

It's called array dereferencing, and should be supported in PHP 5.4. For now you're stuck doing it the way you showed in your second example.

Edit: wanted to add a reference