updating class array member variables in function
Posted: Mon Aug 18, 2008 9:57 pm
Hi
I am new to php.
I have a query. I have a class which has a array member variable list1 and list2. Am trying to update it in a function and not able to.
Here is the class. Please help me.
Code: ( text )
<?php
class simple {
var $list1;
var $list2;
function updateValue() {
$fd = fopen("/mapping", "r");
$i=0;
while(!feof($fd)) {
$info = fscanf($fd, "%s %s\n");
if ($info) {
list($name, $version) =$info;
$this->list1[$i] = $name;
$this->list2[$i] = $version;
$info = null;
$i++;
}
}
fclose($fd);
echo "$this->list1[0]";
echo "$this->list1[1]";
echo "$this->list1[2]";
}
}
?>
I get the response as Array(0), Array(1) and Array(2) instead of strings as dev0, dev1, dev2.
The file has the following:
dev0 1.2.3
dev1 2.4.5
dev2 2.6.7
Thanks & Regards
VP
I am new to php.
I have a query. I have a class which has a array member variable list1 and list2. Am trying to update it in a function and not able to.
Here is the class. Please help me.
Code: ( text )
<?php
class simple {
var $list1;
var $list2;
function updateValue() {
$fd = fopen("/mapping", "r");
$i=0;
while(!feof($fd)) {
$info = fscanf($fd, "%s %s\n");
if ($info) {
list($name, $version) =$info;
$this->list1[$i] = $name;
$this->list2[$i] = $version;
$info = null;
$i++;
}
}
fclose($fd);
echo "$this->list1[0]";
echo "$this->list1[1]";
echo "$this->list1[2]";
}
}
?>
I get the response as Array(0), Array(1) and Array(2) instead of strings as dev0, dev1, dev2.
The file has the following:
dev0 1.2.3
dev1 2.4.5
dev2 2.6.7
Thanks & Regards
VP