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
updating class array member variables in function
Moderator: General Moderators
-
nowaydown1
- Forum Contributor
- Posts: 169
- Joined: Sun Apr 27, 2008 1:22 am
Re: updating class array member variables in function
Welcome to the forum! Drop the string interpolation and you should be good:
Instead of:
Code: Select all
echo $this->list1[0];
echo $this->list1[1];
echo $this->list1[2];
Code: Select all
echo "$this->list1[0]";
echo "$this->list1[1]";
echo "$this->list1[2]";