Hi,
I have problems in trying to '++' an array value.
Every time I find a city I add it in the array,
and if I find it many times I increment the value (counter)
of the city. Here's the code:
$address = "http://www.cji.co.il/bw040609.txt";
$address_local = "bw040609.txt";
$lines = file($address_local);
$heading = "Companies covered in this CJI report:";
$heading_line = 0;
$towns = array();
for($i=0; $i<count($lines); $i++) {
$pos = strpos($lines[$i], "Location: ");
if($pos !== false) {
list($loc,$town) = preg_split("/: /", $lines[$i]);
if(in_array($town, $towns)) {
$towns[$town] = 1;
echo "Town added: $town<br>";
}
else {
$towns[$town]++;
echo "Town added: $town<br>";
}
}
}
foreach($towns as $key => $value) {
print "$key => $value<br>";
}
The output is like this:
Notice: Undefined index: Ramat Hasharon in
C:\Programs\work\jobs\index.php on line 40
Town added: Ramat Hasharon
Notice: Undefined index: North in C:\Programs\work\jobs\index.php on line 40
Town added: North
Town added: North
Notice: Undefined index: Location in C:\Programs\work\jobs\index.php on
line 40
Town added: Location
Town added: Location
Town added: North
Town added: North
and so on...
It complains about an undefined index.
Any idea why it does that?
Shmuel.