PHP array with value returns NULL -


i have array converted csv file. have there 2 keys id , name.

if show key name ok. when tried key id, null key id have value set.

enter image description here

function convertcsvtoarray($filename='', $delimiter=';') {   if(!file_exists($filename))     return false;    $header = null;   $data = array();   if (($handle = fopen($filename, 'r')) !== false)   {     while (($row = fgetcsv($handle, 1000, $delimiter)) !== false)     {       if(!$header)         $header = $row;       else         $data[] = array_combine($header, $row);     }     fclose($handle);   }   return $data; }  $array = convertcsvtoarray('/path/to/csv/categories.csv',';');  /* $array structure   array(2){     ["id"] => 3     ["name"] => name   } */ foreach($array $category){   var_dump($category["id"]); //return null   var_dump($category["name"]); //return "some name" } 

csv dump

id;name 3;značkové nealko nápoje 4;nízkoenergetické nápoje 5;minerálne vody, sóda 6;tetrapack 0.2l 0.5l 

print_r $array

array (     [0] => array         (             [id] => 3             [name] => značkové nealko nápoje         )      [1] => array         (             [id] => 4             [name] => nízkoenergetické nápoje         ) ) 

print_r $category

array (     [id] => 3     [name] => značkové nealko nápoje ) 

the problem here comes bom.

invisible characters added @ begining of file, prefixed "id" key, php can't find id key, , shows null values.

convert csv file utf-8 without bom , fix problem.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -