1

This is my array:

Array
(
    [Soorten] => Array
    (
        [Soort] => inpandig
    )

    [Voorzieningen] => Array
    (
        [Voorziening] => Array
        (
            [0] => voorzien van verwarming
            [1] => voorzien van elektra
            [2] => voorzien van water
            [3] => met elektrische deur
        )
    )

    [Capaciteit] => 1
    (
        [Isolatievormen] => Array
        (
            [Isolatie] => volledig geïsoleerd
        )
    )

How can I display it in PHP, like this:

Voorziening:
voorzien van verwarming
voorzien van elektra
voorzien van water
met elektrische deur

Isolatie:
volledig geïsoleerd

etc.

3
  • 3
    You should read a PHP manual... assoziative arrays is your hint. php.net/manual/de/language.types.array.php Commented Apr 20, 2012 at 14:03
  • A nested foreach, as in foreach ($outer as $k=>$o) { foreach ($inner as $i)} } Commented Apr 20, 2012 at 14:04
  • as most of us are not dutch, try to give english examples. It isn't necessary most of the times, but it makes it easier to comprehend what you are doing, also for non-dutchies :) Commented Apr 20, 2012 at 14:05

1 Answer 1

2

A recursive function would do the trick:

$array = array(
    'Soorten' => array('Soort' => 'inpandig'), 
    'Voorzieningen' => array('Voorziening' => array('voorzien van verwarming', 'voorzien van elektra', 'voorzien van water', 'met elektrische deur')));
printArray($array);

function printArray($array)
{
    foreach($array as $key => $value)
    {
        if(is_array($value))
        {
            echo $key . "<br/>";
            printArray($value);
            echo "<br/>";
        }
        else
        {
            echo $value . "<br/>";
        }
    }
}

Will print:

Soorten
inpandig

Voorzieningen
Voorziening
voorzien van verwarming
voorzien van elektra
voorzien van water
met elektrische deur
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.