PHP解析与多维数组对象stdClass已经 [英] php parsing multidimensional stdclass object with arrays
问题描述
我访问与PHP的一个WSDL web服务。读出的伟大工程,但解析结果似乎有点困难:我试过的var_dump()的结果来得到一个想法,结果怎么样子。这是我的PHP code我用vardump结果:
I am accessing a wsdl webservice with php. Reading out works great but parsing the result seems kinda difficult: I tried to var_dump() the result to get an idea how the result looks like. This is my PHP code I use to vardump the result:
foreach($result as $var => $value) {
var_dump($value);
echo "<br />";
}
这是我得到它:
object(stdClass)#3 (3) {
["Successful"]=> bool(true)
["MessageId"]=> string(0) ""
["MlsMessageText"]=> string(0) ""
}
object(stdClass)#4 (3) {
["RowCount"]=> int(3)
["ColumnCount"]=> int(3)
["Columns"]=> object(stdClass)#5 (1) {
["Column"]=> array(3) {
[0]=> object(stdClass)#6 (2) {
["Name"]=> string(5) "RowID"
["Rows"]=> object(stdClass)#7 (1) {
["string"]=> array(3) {
[0]=> string(5) "12001"
[1]=> string(5) "12002"
[2]=> string(5) "12003" } } }
[1]=> object(stdClass)#8 (2) {
["Name"]=> string(8) "PersonID"
["Rows"]=> object(stdClass)#9 (1) {
["string"]=> array(3) {
[0]=> string(11) "12033310001"
[1]=> string(11) "12033310002"
[2]=> string(11) "12033310003" } } }
[2]=> object(stdClass)#10 (2) {
["Name"]=> string(10) "PersonName"
["Rows"]=> object(stdClass)#11 (1) {
["string"]=> array(3) {
[0]=> string(10) "Jack Jones"
[1]=> string(11) "Jenifer Row"
[2]=> string(12) "Marin Banker" } } }
}
}
}
它是一个相当复杂的答案,我不知道如何与循环解析它。最后,我想获得包含数据的表。
Its a rather complex answer and I have no Idea how to parse it with looping. Finally i want to get a table containing the data.
任何帮助非常一个preciated :)
Any help very apreciated :)
推荐答案
的问题是,他们转表到列 - &GT;行
而不是行 - &GT;列
,你可以通过创建一个新表并扭转列和行。
The problem is that they transposed the table into column -> row
instead of row -> column
, you can do that by creating a new table and reverse the columns and rows.
$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);
顺便说一句, $结果['XXX']
将无法正常工作,在'XXX'
应及时更换正确的关键。
Btw, $result['xxx']
won't work, the 'xxx'
should be replaced with the correct key.
这篇关于PHP解析与多维数组对象stdClass已经的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!