I want to parse JSON string so that I can get it saved into two dimensional array like shown below. Only solution I come with consist of 3 or 4 foreach loops, and I don't think that's good.
{
"root": {
"row": [
{
"Status": "Enabled",
"Keyword": "Toaletna voda",
"Campaign": "Lešenari",
"Adgroup": "Lešenaris",
"BidStrategyType": "InheritFromParent",
"Bid": "0.05",
"Matchtype": "Broad",
"Clicks": "0",
"Impr.": "0",
"Conv.": "0"
},
{
"Status": "Enabled",
"Keyword": "lyžička",
"Campaign": "Lešenari",
"Adgroup": "Lešenaris",
"BidStrategyType": "InheritFromParent",
"Bid": "0.05",
"Matchtype": "Broad",
"Clicks": "0",
"Impr.": "0",
"Conv.": "0"
},
{
"Status": "Search total",
"Keyword": "-",
"Campaign": "-",
"Adgroup": "-",
"BidStrategyType": "-",
"Bid": "-",
"Matchtype": "-",
"Clicks": "0",
"Impr.": "0",
"Conv.": "0"
},
{
"Status": "Content total",
"Keyword": "-",
"Campaign": "-",
"Adgroup": "-",
"BidStrategyType": "-",
"Bid": "-",
"Matchtype": "-",
"Clicks": "0",
"Impr.": "0",
"Conv.": "0"
},
{
"Status": "Deleted items total",
"Keyword": "-",
"Campaign": "-",
"Adgroup": "-",
"BidStrategyType": "-",
"Bid": "-",
"Matchtype": "-",
"Clicks": "0",
"Impr.": "0",
"Conv.": "0"
},
{
"Status": "Overall total",
"Keyword": "-",
"Campaign": "-",
"Adgroup": "-",
"BidStrategyType": "-",
"Bid": "-",
"Matchtype": "-",
"Clicks": "0",
"Impr.": "0",
"Conv.": "0"
}
]
}
}
It Should return something like this
Keyword=>Toaletna voda
Keyword=>lyžička
Campaign=>Lešenari
Campaign=>Lešenari
Adgroup=>Lešenaris
Adgroup=>Lešenaris
Bid=>0.05
Bid=>0.05
Clicks=>0
Clicks=>0
Impr.=>0
Impr.=>0
Conv.=>0
Conv.=>0
It should do same thing as this function, it takes array of names, and find values that are append to it in that xml file
public function LoadXmlReport($adSystemColumns = array())
{
require "config.php";
$xmlfile = simplexml_load_file(dirname(__FILE__) . "/xmlfile.xml");
foreach ($xmlfile as $key => $value)
foreach ($value as $columnName => $item) {
if ($item == "-") {
break;
} elseif (array_search($columnName, $bing) !== FALSE)
$this->report[$columnName][] = $item;
}
foreach ($this->report as $key => $value)
foreach ($value as $index => $item)
echo $key."=>".$item."<br/>";
}
those are the values
$bing = array(
"Adgroup",
"Campaign",
"Keyword",
"Clicks",
"Impr.",
"Conv.",
"Bid",
"Adgroup"
);
Keywordso I want value of every cell below assign toarray["Keyword"][]. And actually, i have working method for csv format, but when i am looking on my xml method I am not sure it is possible, because if the xml file is nested one more time then I need another loop.