I am trying to explode a string into a list based off comma's, I have done this before but for some reason this not working now.
Just for reference, the line where I called echo echo $members[6];
returns 2009, 7, 146, 277.00, Company 6
so I know everything is being stored properly into $members
I also know from calling $arrlength
it returns the correct size of strings that I populate into $members
.
So I have the right data and it is formatted correctly yet the ONLY lines that print on my index.php is the echo $members[6];
statement and since I have a VERY long scroll bar I am also guessing that echo "<br><br>";
prints too.
Any help would be greatly appreciated.
<html>
<head>
</head>
<body>
<?php
$str_data = file_get_contents("file.json");
$data = json_decode($str_data,true);
foreach ($data as $key => $value)
{
foreach ($value as $k => $v)
{
$t = "";
foreach ($v as $kk => $vv)
{
$t = $t . ", " . $vv;
}
$members[] = substr($t, 2); //cuts out initial comma + space
}
}
$arrlength=count($members);
echo $members[6]; // returns 2009, 7, 146, 277.00, Company 6
for ($i=0; $i<$arrlength; $i++)
{
list($year, $rank, $revenue, $profit, $company) = explode(",", $members[i]);
$year = trim($year);
$rank = trim($rank);
$revenue = trim($revenue);
$profit = trim($profit);
$company = trim($company);
echo $year;
echo $rank;
echo $revenue;
echo $profit;
echo $company;
echo "<br><br>";
}
?>
</body>
</html>