I'm working on a little thing for uni. However, the following is a small problem in the whole thing, which keeps me from progressing.
I read in a file containing the data on the names and want to sort it depending on the different details using if-statements so far. This is where the problem occurs:
for($i ;$i < count($file); $i++){
if($i>0) {
$data = explode(",", $file[$i]);
echo $data[0] . $data[1] . $data[2] . $data[3] . $data[4]; //this works
?><br /><?php
//The following one works too.
if($data[0] == "Ann"){
echo $data[0];
?><br /><br /><?php
}
// All these don't work
if($data[3] == "californien") {
echo 'Name: '. $data[0] . ', Occurences: '. $data[4];
?><br /><?php
}
if($data[2] == "20-30"){
echo $data[0];
?><br /><?php
}
if($data[1] == "w"){
echo $data[0];
?><br /><?php
}
}
}
A sample from the csv file looks like this:
(Name, sex, year interval, state, occurences)
Mary, w, 10-20, californien, 88
Just using echo on some of the $data array elements works fine. Using the if-statement on the name ($data[0]) works, too. But if I wanna use any of the other parts like the interval, state sex, or occurrences it doesn't show anything at all.
I guess and hope it's just a small thing I didn't notice.
Anyone know what's wrong?
print_r($data)after$data = explode(",", $file[$i]);. Would definitely help a lot.echo '<br>';instead of?><br /><?php.trim()like:-if(!empty(trim($data[3])) && trim($data[3]) == "californien") {and so on for othhers[space]something!==something