【问题标题】:Looping through a object(stdClass)循环对象(stdClass)
【发布时间】:2013-06-23 21:39:46
【问题描述】:

我看到了这个例子,但仍然不知道如何去做

问题是他们将表格转换为列 -> 行而不是行 -> 列,您可以通过创建一个新表格并反转列和行来做到这一点。

$table = array();

foreach ($result['xxx']->Columns->Column as $colnr => $coldata) {
    foreach ($coldata->Rows->string as $rownr => $rowdata) {
        $table[$rownr][$coldata->Name] = $rowdata;
    }
}

print_r($table);

可以帮助我遍历这些数据,计划将数据显示为表格 结果与 var_dump($result->result);

object(stdClass) #5 (1) { 
    ["complexObjectArray"]= > array(5) {
        [0] = > object(stdClass) #6 (105) { 
            ["increment_id"]= > string(9) "100000118" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-04-21 07:14:34"
        }
        [1] = > object(stdClass) #7 (104) { 
            ["increment_id"]= > string(9) "100000128" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-04-22 09:50:27" 
        }
        [2] = > object(stdClass) #8 (105) { 
            ["increment_id"]= > string(9) "100000133" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-04-24 07:43:40" 
            ["updated_at"] = > string(19) "2013-04-27 14:50:23" 
        }
        [3] = > object(stdClass) #9 (108) { 
            ["increment_id"]= > string(9) "100000156" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-05-07 14:41:30" 
        } 
    }
}

我正在考虑这个问题

    foreach($result as $complexObj){
foreach($complexObj as $totalArray){
foreach($totalArray as $item){

echo $item->["increment_id"];
}
}
}

【问题讨论】:

  • @dleiftah 感谢格式化它,我正在考虑如何做到这一点:x

标签: php object


【解决方案1】:

试试这个:

foreach($result->result->complexObjectArray as $item){
    echo $item->increment_id;
}

【讨论】:

  • 没有显示任何东西,甚至 var_dump($item)。我正在查看stackoverflow.com/questions/950827/…,这似乎与我的问题非常相似,我正在努力理解它:(
  • @RainbowHat 如果var_dump($result) 产生你上面的转储,那么这应该可以工作。尝试在循环之前执行var_dump($result->complexObjectArray) ...应该显示您想要循环的数组。如果不是,则 $result 不在您在上面发布的结构中
  • 循环前显示 NULL var_dump($result->complexObjectArray)
  • 那么$result 不包含您在上面提供的转储。转储来自哪个变量?转储$result 会得到什么?
  • 上面其实是 var_dump($result->result);对不起:x
猜你喜欢
  • 1970-01-01
  • 2010-10-31
  • 2016-03-14
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 2015-10-24
  • 2012-04-05
  • 2014-01-31
相关资源
最近更新 更多