调用PHP会爆炸并访问第一个元素? [英] Calling PHP explode and access first element?
问题描述
可能重复:
用于取消引用函数结果的PHP语法
Possible Duplicate:
PHP syntax for dereferencing function result
我有一个字符串,看起来像 1234#5678 .现在我叫这个:
I have a string, which looks like 1234#5678. Now I am calling this:
$last = explode("#", "1234#5678")[1]
它不起作用,存在一些语法错误...但是在哪里?我期望的是$last
中的5678.这在PHP中不起作用吗?
Its not working, there is some syntax error...but where? What I expect is 5678 in $last
. Is this not working in PHP?
推荐答案
在当前的PHP版本中无法进行数组取消引用.但是您可以使用 list
[docs] a>直接将数组元素分配给变量:
Array dereferencing is not possible in the current PHP versions (unfortunately). But you can use list
[docs] to directly assign the array elements to variables:
list($first, $last) = explode("#", "1234#5678");
更新
自PHP 5.4(2012年3月1日发布)以来,它支持数组解引用.
Since PHP 5.4 (released 01-Mar-2012) it supports array dereferencing.
这篇关于调用PHP会爆炸并访问第一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!