I hope you can help me with this awkward issue.
I am trying to get a certain value from all rows in a csv file,all works good until in_array().
CSV File looks like this :
Mach Vu,11-25-2012 21:32:39,row1
Mach Vu,11-25-2012 21:32:46,row2
I am trying to get last value from each row (i.e. ‘row1′,’row2’).
Here is my code :
$i = 1;
foreach($array2 as $key=>$value) {
foreach($array2[$key] as $value2) {
if($i % 3 == 0) {
$array3[] = $value2;
}
$i++;
}
}
print_r($array3);
echo "<br />";
if(in_array("row1", $array3)) {echo "yes";} else {echo "no";}
Array 3 is printing :
Array (
[0] => row1
[1] => row2
)
Thanks in advance for help ! All the best !
This may solve it for you, while also trimming down your code a bit and drastically improving performance.
My guess is that in_array isn’t working due to extra whitespace, thus the addition of the trim()