I want help on this block of code
foreach ($summary as $key => $value)
{
if ($key === "Incs") {
foreach ($value as $subkey => $subvalue) {
foreach ($subvalue as $subsubkey => $subsubvalue) {
echo "$subsubkey:\n";
foreach ($subsubvalue as $subsubsubkey => $subsubsubvalue) {
echo $subsubsubvalue;
}
}
}
} else {
echo "$key: $value\n";
}
}
that is working by printing values of sub array echo $subsubsubvalue; but I want to use key to access each value like echo $subsubsubvalue[$subsubsubkey]; which seems to generate error. Is there anyway possible to achieve that?
foreach ($summary as $key => $value)
{
if ($key === "Incs") {
foreach ($value as $subkey => $subvalue) {
foreach ($subvalue as $subsubkey => $subsubvalue) {
echo "$subsubkey:\n";
foreach ($subsubvalue as $subsubsubkey => $subsubsubvalue) {
echo $subsubsubvalue[$subsubsubkey];
}
}
}
} else {
echo "$key: $value\n";
}
}
Here is the array Wich I am trying print
array(8) { ["Eid"]=> string(6) "891551" ["Tr1"]=> string(1) "2" ["Tr2"]=> string(1) "0" ["Trh1"]=> string(1) "2" ["Trh2"]=> string(1) "0" ["Tr1OR"]=> string(1) "0" ["Tr2OR"]=> string(1) "0" ["Incs"]=> array(1) { [1]=> array(2) { [0]=> array(12) { ["Min"]=> int(24) ["Nm"]=> int(1) ["Aid"]=> string(5) "57092" ["ID"]=> string(5) "57092" ["Fn"]=> string(7) "Si-heon" ["Ln"]=> string(3) "Lee" ["Pnum"]=> int(0) ["Pn"]=> string(11) "Si-Heon Lee" ["PnumO"]=> int(0) ["IT"]=> int(36) ["Sc"]=> array(2) { [0]=> int(1) [1]=> int(0) } ["Sor"]=> int(3) } [1]=> array(9) { ["Min"]=> int(32) ["Nm"]=> int(1) ["ID"]=> string(7) "1067481" ["Pnum"]=> int(0) ["Pn"]=> string(13) "Dong-Ryul Lee" ["PnumO"]=> int(0) ["IT"]=> int(36) ["Sc"]=> array(2) { [0]=> int(2) [1]=> int(0) } ["Sor"]=> int(5) } } } }
I want to show them in table Time | Player | Incident
36'. Debryne. Goal 45'. Martial. Yellow card
var_export($summary);in your question that would help us a lot. See also How to Ask and how to produce a minimal reproducible example of your issue. You can edit your post. Thanks.$subsubsubkeyis a key of$subsubvalue, not$subsubsubvalue. So you could writeecho $subsubvalue[$subsubsubkey];.$subsubsubvalueeasier to write?$subsubvalue[$subsubsubkey]were another array that has the same key as$subsubvalue. But in that case the first code wouldn't work because you can't echo arrays.