正确访问数组[重复]

This question already has an answer here:

I've seen people write code like this:

$image_url =  wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(300, 300), false, ''); 
$image_url = $image_url[0];

which seems a little ridiculous because you could just attach the [0] to the end of the first term. So I never did it in my local machine, but now when deploying to remote machines (with possibly different versions of php, I always get bugs about unexpected '['. Does php not accept accessing arrays in-place, or was there some change in some version?

</div>

This is allowed since PHP 5.4:

Function array dereferencing has been added, e.g. foo()[0].

Which version of PHP are you using? Function array dereferencing is allowed in PHP 5.4 (and above).

In PHP < 5.4, you can't take an element from an array before it exists... You must come from a Python or Ruby world where this kind of syntax is allowed.

If you have PHP < 5.4, you have to set the array and after get the index you want.