PHP: How to access the first element of an array returned by a static function
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4639265/php-explode-and-array-index">php explode and array index</a>  </p>
</blockquote>



<p>In PHP 5.3...</p>

<p>I have a dynamic static method that always returns an array. In some cases it will return an array containing only one element. I want to assign, in one statement, the first element of the array to a variable. At the moment I have to do this:</p>

<pre><code>$user = User::findByEmail($_SESSION['email']);
$user = $user[0];
echo $user;
</code></pre>

<p>I want to avoid the part...</p>

<pre><code>$user = $user[0];
</code></pre>

<p>I expect something like this to work:</p>

<pre><code>$user = User::findByEmail($_SESSION['email'])[0]; // not working
</code></pre>

<p>or</p>

<pre><code>$user = User::findByEmail($_SESSION['email'])-&gt;get(0); // not working
</code></pre>

<p>or</p>

<pre><code>$user = User::findByEmail($_SESSION['email']).get(0); // not working
</code></pre>
