I have the following code to parse data from a multidimensional array which is from a csv file:
//I=1, damit mit der 2. Spalte begonnen wird.
for ( $i = 1; $i < $anzahlspalten; $i++ ) {
$product = new ZubehoerProdukt();
foreach ( $locations as $zeile => $bezeichner ) {
echo "Aktueller Bezeichner: " . $bezeichner . " in Zeile ". $zeile . "<br/>";
if( $bezeichner == "Produktname" ) { die("Bezeichner Produktname gefunden"); }
elseif ( $bezeichner == "Produkttype") { $product->ProduktType = $this->zubehoerArray[$zeile][$i]; }
elseif ($bezeichner == "Art.-Code:") { $product->SKU = $this->zubehoerArray[$zeile][$i]; }
elseif ($bezeichner == "Beschreibung lang") { $product->beschreibung_lang = $this->zubehoerArray[$zeile][$i]; }
elseif ($bezeichner == "Beschreibung kurz") { $product->beschreibung_kurz = $this->zubehoerArray[$zeile][$i]; }
elseif ($bezeichner == "Produktname") { $product->ProduktName = $this->zubehoerArray[$zeile][$i]; }
else { }
}
$products[] = $product;
}
The problem: If the $bezeichner variable is "Produktname" it is not working.
The $locations array contains the following data:
Array
(
[0] => Produktname
[1] => Produkttype
[2] => Art.-Code:
[5] => Anschluss
[6] => Beschreibung kurz
[7] => Beschreibung lang
[8] => Produktbilder-Dateinamen
)
My debug-echo also outputs: "Aktueller Bezeichner: Produktname in Zeile 0"
I have the impressum that array-key 0 is not parsed correctly, but I don't find the mistake. Any idea why it is not working?