1

I have an array (a line of an csv file). This array contains the following data (var_dump($rowData)).

array(8) {
  ["Kategorie"]=>
  string(12) "Bio- Bäcker"
  ["Name"]=>
  string(31) "A nice name"
  ["Adresse"]=>
  string(27) "the street 13"
  ["PLZ"]=>
  string(5) "08056"
  ["Ort"]=>
  string(7) "Zwickau"
  ["Tel"]=>
  string(14) "0375/390 xxx"
  ["Mail"]=>
  string(24) "[email protected]"
  ["Website"]=>
  string(27) "http://doktor-xxx.xx/"
}

By getting values by running $rowData['key'] I get an error - but only by the first array key (Kategorie). PHP is telling me, the key doesn't exists.

I tried something around, all other keys are callable, but not the first.

$profileName = $rowData['Name'];
$profileAddress = $rowData['Adresse'];
$profileZip = $rowData['PLZ'];
$profileCity = $rowData['Ort'];
$profilePhone = $rowData['Tel'];
$profileWebsite = $rowData['Website'];
$profileMail = $rowData['Mail'];
$profileCategory = $rowData['Kategorie'];

Just don't know what's wrong with my code...

32
  • 1
    Try $rowData->Kategorie it might work that way instead Commented Aug 11, 2017 at 15:46
  • 2
    It is an array, not an object! Commented Aug 11, 2017 at 15:48
  • 1
    Maybe you have some hidden character in the key. Try var_dump(array_keys($rowData)) to see if the key length matches what you expect Commented Aug 11, 2017 at 15:49
  • 4
    Kategorie is definitely not 12 characters; looks like a charset discrepancy to me Commented Aug 11, 2017 at 16:00
  • 1
    @yanman1234 No, that refers to "Kategorie", it is a dump of array_keys(.....) (I assume). Commented Aug 11, 2017 at 16:03

1 Answer 1

2

Actually there are hidden characters in the key name - by running this code, it works:

foreach ($rowData as $key => $value) {
    $newKey = str_replace('?', '', utf8_decode($key));
    $rowData[$newKey] = $value;
}

Maybe not the best solution, but it works (in this case).

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.