0

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?

4

3 回答 3

4

PHP 5.4起允许这样做:

添加了函数数组解引用,例如 foo()[0]。

于 2013-08-04T18:58:14.883 回答
1

您使用的是哪个版本的 PHP?PHP 5.4(及更高版本)允许函数数组取消引用。

于 2013-08-04T18:59:05.383 回答
1

PHP < 5.4中,您不能在数组存在之前从数组中获取元素……您必须来自允许这种语法的 Python 或 Ruby 世界。

如果你有 PHP < 5.4,你必须设置数组并在获得你想要的索引之后。

于 2013-08-04T19:00:04.997 回答