[英]how can iterate inner array of 7 and 51 in php
How can I get the values of 51
and 7
through iteration.如何通过迭代获得
51
和7
的值。
Array
(
[686] => Array
(
[51] => Array
(
[0] => 1483691174
[1] => 1483691174
)
[7] => Array
(
[0] => 1483691174
[1] => 1483691174
[2] => 1483691174
[3] => 1483691174
[4] => 1483691174
[5] => 1483691174
[6] => 1483691174
[7] => 1483691174
[8] => 1483691174
[9] => 1483691174
[10] => 1483691174
[11] => 1483691174
[12] => 1483691174
[13] => 1483691174
[14] => 1483691174
)
)
)
This function can be used to iterate any level of array with sub array:-此函数可用于使用子数组迭代任何级别的数组:-
function iteratetor(){
static $cnt = 0;
$args = func_get_args();
if (!empty($args)) {
echo '<ol>';
foreach ($args as $k => $v) {
if(in_array($k,array('7','51'))){
$v = htmlspecialchars(print_r($v, true));
if ($v == '') {
$v = ' ';
}
echo '<li><pre>' . $v . "\n" . '</pre></li>';
}
}
echo '</ol>';
}
$cnt++;}
just expand the statament in_array($k,array('7','51')) to suite your spec只需扩展 statament in_array($k,array('7','51')) 以适应您的规格
you need to loop through the inner array and to get there you need arrays inside 686
.您需要遍历内部数组并到达那里,您需要
686
内部的数组。 use foreach()
to get this done.Try this: .使用
foreach()
完成此操作。试试这个:
foreach($arr as $arrs){
foreach($arrs as $key=>$val){
echo "For:".$key."::::::::::<br>";
foreach($val as $k=>$value){
echo $k." =>".$value."<br>";
}
}
}
Iterate it like this:像这样迭代它:
foreach($array[686] as $k => $v)
{
echo $k."\n";
var_dump($v);
}
You can try other way,你可以试试其他方式
<?php
print_r(array_column($arr, 7));
print_r(array_column($arr, 51));
?>
You can check output here您可以在此处检查输出
array_column : Return the values from a single column in the input array array_column :返回输入数组中单列的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.