Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I wanted to show everything what is on the arrays but it doesn't seems to show all information, and each server might have more than 2 partition, below I written was just 2 partition, other server might have more than 2. Is it possible to detect how many partition inside the server and display all? below is my code:-

<?php
$rangehourly = "129600";
$rangedaily = "604800";

$graph_list = array(
 'myserver.com' => array(

  '/home' => array(
   'daily'=> 'https://longserverurlhere.com',
   'hourly'=> 'https://longserverurlhere.com'
  ),

  '/var/www/html/' => array(
   'daily'=> 'https://longserverurlhere',
   'hourly'=> 'https://longserverurlhere'
  )
 )
);


 foreach($graph_list as $servername => $value) {
    echo $servername . "<br />";
    foreach($value as $a => $part) {
        echo $a .'<br>'. $part[0].'<br>'.$part[1];

    foreach($part as $b => $range) {
    echo $b . '<br>'. $range[0]. '<br>'.$range[1];

    }
    }
    echo "<br> /><br />";
}
?>

I tried adding another foreach loop, it shows me invalid argument. Ignore the variables it will placed with url once it this issue is solved.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

I suppose code should look like this:

<?php
$rangehourly = "129600";
$rangedaily = "604800";

$graph_list = array(
 'myserver.com' => array(
  '/home' => array(
   'daily'=> 'https://longserverurlhere.com',
   'hourly'=> 'https://longserverurlhere.com'
  ),
  '/var/www/html/' => array(
   'daily'=> 'https://longserverurlhere',
   'hourly'=> 'https://longserverurlhere'
  )
 )
);

foreach ($graph_list as $servername => $value) {
    echo htmlspecialchars($servername) . '<br>';
    foreach ($value as $folder => $ranges) {
        echo htmlspecialchars($folder) .'<br>';
        foreach ($ranges as $rangeName => $range)
            echo htmlspecialchars($rangeName) . '<br>' . htmlspecialchars($range) . '<br>';
    }
    echo '<br>';
}
?>
share|improve this answer
 
Thanks! Works like charm! –  Furry Feb 11 at 9:17
add comment

Try using

var_dump($array);

or

print_r($array);

If you choose the latter, I recommend adding this before that line:

echo "<pre>";

EDIT

HEHE. You edit it. I thought this is what you were looking for.

share|improve this answer
 
Done a var_dump($array) to see it ;) –  Nanis Feb 11 at 8:55
 
also try using these with xdebug too. –  Hilmi Erdem KEREN Feb 11 at 8:56
add comment

Your keys are keywords, and you try to use numbers.

foreach($graph_list as $servername => $value) {
   echo $servername . "<br />";
   foreach($value as $a => $part) {
       echo $a .'<br>'. $part['daily'].'<br>'.$part['hourly'];
   }
   echo "<br> /><br />";
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.