-2

How to nicely display the data structure. Below paste my multidimensional array, please help

        Array
        (
            [1] => Array
                (
                    [0] => Array
                        (
                            [LP] => 1
                            [Produkt] => product1
                        )
                )
            [2] => Array
                (
                    [0] => Array
                        (
                            [LP] => 2
                            [number] => 157/03/2014
                            [Produkt] => product1
                        )
                    [1] => Array
                        (
                            [LP] => 2
                            [number] => 157/03/2014
                            [Produkt] => product2
                        )
                )
        )

=== My CODE ==============================================

foreach ($a as $date) {
        $output .= "\t\t\t<ID>". $date[0]['LP']."</ID>\n";

        second foreach for product {
        $output .= "\t\t\t<Produkt>". Produkt ."</Produkt>\n";
        }
    }

1 Answers1

0

i'm not sure i understand what you wanna do. if you want to write to screen

foreach ($a as $date) {
    foreach ($date as $product) {
        $date_lp = $product['LP'];
        if ($date_lp !== $last_date_lp) {
            $last_date_lp = $date_lp;
            $output .= "\t\t\t<ID>{$date_lp}</ID>\n";
        }
        $output .= "\t\t\t<Produkt>{$product['Produkt']}</Produkt>\n";
    }
}

if your intention is to convert this array to xml then read this question about converting associative array to xml.

oriadam
  • 7,747
  • 2
  • 50
  • 48