I'm trying to parse a CSV file and read its contents. I get file like this:
$lines = file(base_path() . '/storage/data/test.csv', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
After that, I use dd($lines) to get its output and it's like this:
array:4 [
0 => "Column1,Column2,Column3"
1 => "row11,row12,row13"
2 => "row21,row22,row23"
3 => "row31,row32,row33"
]
Which is okay so far. I'm exploding every line.
$check = 'Column1';
foreach ($lines as $line) {
$exploded = explode(',', $line);
if (($index = array_search($check, $exploded)) !== false) {
echo $index;
}
}
I can get every index of that $exploded array for matching value. Except "Column1", A1 value. I've also checked that after the first explode function:
dd(trim($exploded[0]) === trim($check))
It's printing "false". But I've printed them both, and they are both "Column1". Is there anything I'm missing?