Foreach上升1 php [英] Foreach go up by 1 php

查看:79
本文介绍了Foreach上升1 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读出一些接入点的信息.这些访问点已编号,此时代码中的[0]站必须在循环中上移1.然后循环可以再次运行并读出第二个AC的信息,依此类推.

I want to read out the information of some access points. These access points are numberd where in the code at this moment [0] stand has to go up by 1 in the loop. then the loop can run again and read out the information of the second AC and so on.

$name      = $ac0->result[0]->name;
$status    = $ac0->result[0]->status;
$uptime    = $ac0->result[0]->uptime;
$last_seen = $ac0->result[0]->last_seen;

所有代码

foreach ($ac0->result as $key => $value) { 
    $name0 = $ac0->result[0]->name; 
    $status0 = $ac0->result[0]->status; 
    $uptime0 = $ac0->result[0]->uptime; 
    $last_seen0 = $ac0->result[0]->last_seen; 
} 

推荐答案

$ac0->result开始循环,然后在$obj中找到所有属性,或者在foreach循环中调用它的任何内容

Start the loop at the $ac0->result and then all the properties will be found in the $obj or whatever you like to call it in the foreach loop

foreach ($ac0->result as $idx => $obj) {
    echo "From Array $idx <br>";
    echo $obj->name . "<br>";
    echo $obj->status . "<br>";
    // etc
}

这篇关于Foreach上升1 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆