Flynn
Flynn

Reputation: 193

Issues with php nested arrays

Basically I'm using this library someone put together to return information from my minecraft server. Everything works, except for this page I just want to list the mods and their version numbers. You can see the output here: http://litcraft.net/view2.php

As you can see, it's just using a loop to dump the information to the page. All I'm trying to do is go into the last array "modinfo" and ONLY pint out the modid and version in a list. I can format it once I get it, but I'm having an issue printing that list. Here is the code for what there is now:

<?php foreach( $Info as $InfoKey => $InfoValue ): ?>
    <tr>
        <td><?=htmlspecialchars($InfoKey); ?></td>
        <td><?php
if($InfoKey === 'favicon'){
    echo '<img width="64" height="64" src="' . Str_Replace("\n","",$InfoValue) . '">';
}else if(Is_Array($InfoValue)){
    echo "<pre>";
    print_r($InfoValue);
    echo "</pre>";
}else{
    echo htmlspecialchars( $InfoValue );
}
?></td>
                </tr>
<?php endforeach; ?>

So I tried to do this to dig into the array and print out only the mod list:

<?php 
$len = count($Info['modinfo']['modList']) + 1;
echo "<p>There are " . $len . " mods.</p>";
for($i=0;$i<$len;$i++){
    foreach($Info['modinfo']['modlist'][$i] as $ModID => $ModVersion): ?>
                <tr>
                    <td><?=$ModID; ?></td>
                    <td><?=$ModVersion; ?></td>
                </tr>
    <?php endforeach;
}?>

And all I get is the error you see on the page 175 times.... What am I doing wrong? I know it has to be something simple, but it's all starting to blend together at this point lol.

Upvotes: 1

Views: 74

Answers (1)

Prashant Valanda
Prashant Valanda

Reputation: 480

You can also do instead of foreach

echo $Info['modinfo']['modlist'][$i]['modid'] ;
echo $Info['modinfo']['modlist'][$i]['version'] ;

Upvotes: 2

Related Questions