I have a multidimensional array that I am trying to parse through and it is throwing back weird results (or I am just overlooking something simple). Here is a sample print_r of the json_decode from the beginning:
Array
(
[DateGenerated] => 2014-01-12T19:30:21.897
[Corporation] => Array
(
[CorporateBuilderNumber] => MHI
[CorporateState] => TX
[CorporateName] => McGuyer Homebuilders, Inc.
[Builder] => Array
(
[0] => Array
(
[BuilderNumber] => COV
[BrandName] => Coventry Homes
[ReportingName] => Coventry Homes
[DefaultLeadsEmail] => [email protected]
[BuilderWebsite] => http://www.coventryhomes.com
[Subdivision] => Array
When using this code:
<?php
mysql_connect("localhost", "", "");
mysql_select_db("");
$json_data = file_get_contents('mhi.json');
$json = json_decode($json_data, true);
foreach ($json as $value) {
echo $value['CorporateBuilderNumber'] . "<br />";
echo $value['CorporateState'] . "<br />";
echo $value['CorporateName'] . "<br />";
}
?>
I get this as the output:
2
2
2
MHI
TX
McGuyer Homebuilders, Inc.
Where is that 2 coming from?
foreach ($json as $key=>$value)?$keyin a foreach statement. I feel like the 2's are probably coming from some earlier code. What do you have before your foreach statement?$value['Corporation']['CorporateBuilderNumber'],$value['Corporation']['CorporateState'],$value['Corporation']['Builder'][0]['BuilderNumber'], and so forth.