Question: any idea how if the following is possible in PHP as a single line ?:

```
<?php
$firstElement = functionThatReturnsAnArray()[0];

```

... It doesn't seem to 'take'. I need to do this as a 2-stepper:

```
<?php
$allElements = functionThatReturnsAnArray();
$firstElement = $allElements[0];

```

... just curious - other languages I play with allow things like this, and I'm lazy enoug to miss this in PHP ... any insight appreciated ...

Answer: 
You *can* do this in one line! Use [array\_shift()](http://us.php.net/array_shift).

```
<?php

echo array_shift(i_return_an_array());

function i_return_an_array() {
    return array('foo', 'bar', 'baz');
}

```

When this is executed, it will echo "`foo`".
If it's always the first element, you should probably think about having the function return just the first item in the array. If that is the most common case, you could use a little bit of coolness:

```
function func($first = false) {
    ...
    if $first return $array[0];
    else return $array;
}

$array = func();
$item = func(true);

```

My php is slightly rusty, but i'm pretty sure that works.

You can also look at array\_shift() and array\_pop().

This is probably also possible:

```
array(func())[0][i];

```

The 0 is for the function.