如何访问函数返回数组的元素? [英] How to access the elements of a function's return array?
本文介绍了如何访问函数返回数组的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从一个函数中返回多个值,因此我将它们添加到一个数组中并返回了该数组.
I need to return multiple values from a function, therefore I have added them to an array and returned the array.
<?
function data(){
$a = "abc";
$b = "def";
$c = "ghi";
return array($a, $b, $c);
}
?>
如何通过调用上述函数来接收$a
、$b
、$c
的值?
How can I receive the values of $a
, $b
, $c
by calling the above function?
推荐答案
您可以将数组键添加到返回值中,然后使用这些键打印数组值,如下所示:
You can add array keys to your return values and then use these keys to print the array values, as shown here:
function data() {
$out['a'] = "abc";
$out['b'] = "def";
$out['c'] = "ghi";
return $out;
}
$data = data();
echo $data['a'];
echo $data['b'];
echo $data['c'];
这篇关于如何访问函数返回数组的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文