访问通过函数返回数组 [英] Access an Array Returned by a Function
本文介绍了访问通过函数返回数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
反正是有直接访问数组中返回的数据没有一个临时变量?
Is there anyway to directly access the data returned in an array without a temporary variable?
目前,我的code是如下:
Currently, my code is as follows:
function getData($id) {
// mysql query
return mysql_fetch_array($result);
}
$data = getData($id);
echo $data['name'];
有没有直接的方法去得到返回的数据,而临时变量?
Is there a direct way to get the returned data without the temporary variable?
推荐答案
PHP 5.4中加入阵解引用,这里是从PHP的的例子阵列文档:
PHP 5.4 added array Dereferencing, here's the example from PHP's Array documentation:
示例#7数组间接引用
function getArray() {
return array(1, 2, 3);
}
// on PHP 5.4
$secondElement = getArray()[1];
// previously
$tmp = getArray();
$secondElement = $tmp[1];
这篇关于访问通过函数返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文