如何使用php传递和访问数组变量 [英] How to pass and access the array variable using php
问题描述
我有一个数组$ param,同时给Print_r时,输出如下,
I have a array $param and while giving Print_r, the output as follows,
Array (
[pattern] =>
[status] => Array ( [0] => 0 [1] => 4 )
)
我必须将状态值传递给一个函数,例如
I have to pass the status value to one function like,
function value($action, $param){
// want to use the value here
}
我如何在这里获得价值。请帮忙
how can i get the value here. please help
推荐答案
如果要将多维数组作为参数传递,只需传递名称为的子数组
If you want to pass a multi-dimensional array as a parameter, simply pass the child array with the name of the parent (container array).
因此,如果像
Array (
[pattern] =>
[status] => Array (
[0] => 0
[1] => 4
)
)
如果您想同时使用 status的两个元素
传递给函数,传递数组父级的名称。 (在这种情况下, param )
if you want both the elements of status
to be passed into the function,pass the name of the array parent. (in this case, param)
function foo($x)
{
echo "<pre>"; // just to make reading easy ;)
print_r($x);
}
函数foo()
显示传递给函数的内容,您可以使用该函数查看传递的内容。
The function foo()
displays the contents passed into the function which you can use to see what's being passed.
诸如 foo($ param ['status'])
给出了这个:
so things like foo($param['status'])
gives this :
Array( [0] => 0 [1]=> 4 )
以及 foo($ param ['status'] [1])
给出了以下内容:
4
这篇关于如何使用php传递和访问数组变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!