0

I have and array called $team in PHP that looks like this:

array(22) { ["league_name"]=> string(28) "1.súdánská liga 2020/2021" ["league_id"]=> string(6) "173720" ["sport_id"]=> string(3) "301" ["team_id"]=> string(6) "743616" ["team_name"]=> string(16) "Al Ahli Khartoum" ["display_name_long"]=> string(16) "Al Ahli Khartoum" ["display_name_short"]=> string(16) "Al Ahli Khartoum" ["when_added"]=> string(19) "31.12.2020 11:36:25" ["LV_team"]=> string(1) "." ["PZ_team"]=> string(1) "." ["Bc_team"]=> string(1) "." ["Bc_team_id"]=> string(1) "." ["Su_team"]=> string(1) "." ["Su_team_id"]=> string(1) "." ["To_team"]=> string(1) "." ["To_id"]=> string(1) "." ["LS_team"]=> string(1) "." ["LS_id"]=> string(1) "." ["eW_team"]=> string(1) "." ["eW_id"]=> string(1) "." ["bX_team"]=> string(1) "." ["bX_id"]=> string(1) "." }

I can echo any element from that table using for example:

echo $team['team_id'] to get "743616"

But I can't use echo $team['league_name'] to get "1.súdánská liga 2020/2021"

I'm receiving error: Undefined index: league_name in xxx.php on line xxx. It's not the first time I'm having problems with 1st element in array. Array is made from csv file (don't know if that info is needed).

UrukMorg
  • 7
  • 3
  • There's a Unicode BOM at the start of the key league_name. If you copy it from your question into an editor that shows special characters, you'll see it: https://3v4l.org/dkOQP. Note how the output says the string is 14 characters long - 11 for league_name, plus 3 for the BOM. You need to either remove this from your CSV file, or remove it as part of the import process. – iainn Dec 31 '20 at 11:07
  • So the issue was exactlly as You described, I used this fseek($handle, 3); when importing data from csv and it solved the problem. THANKS a lot, I wasted so much time, while I should ask experts – UrukMorg Dec 31 '20 at 11:47

1 Answers1

0

Did you check UTF8? Maybe special characters are causing the problem.

Yann
  • 67
  • 9
  • I have also special characters in the other columns and it's working. Mainly what I don't understand is why error message is saying Undefined index, while in var_dump we can clearly see that is exists. – UrukMorg Dec 31 '20 at 10:56
  • I don't see special characters as 'à' in the other columns, try to remove it and try again – Yann Dec 31 '20 at 10:58
  • You don't see because what I'm showing here is just 1 line of bigger array. But I changed it to ["league_name"]=> string(13) "Sudan/1.Sudan" and it's stil lshowing the same error "Undefined index: league_name in ..." – UrukMorg Dec 31 '20 at 11:02