dynamic array in objects??
| From: | Giovanni Lenzi | Date: | Tue, 16 Apr 2002 21:24:08 +0000 |
| Subject: | dynamic array in objects?? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-93257@lists.php.net to get a copy of this message | ||
How can i build a dynamic array as a member of a class??
I have the class SELECT and i want its attribute "VALUES" to be set like an
array.
It is possible??
Array would be built in the constructor of the class.
This is my example:
class Select
{
// ~ options separator ^ value-description
separator
var $values;
var $descs;
function Select($list="")
{
echo $list."<br>";
$options = explode("~",$list);
for($i=0; $i<count($options); $i++)
{
$splitted = explode("^",$options[$i]);
echo $splitted[0]."-".$splitted[1]."<br>";
$this->$values[$i] = $splitted[0];
$this->$descs[$i] = $splitted[1];
echo $this->$values[$i]."-".$this->$descs[$i]."<br><br>";
}
}
$sel = new Select("pera^PERA~banana^BANANA~mela^MELA");
i run the script and the result is:
pera^PERA~banana^BANANA~mela^MELA
pera-PERA
PERA-PERA
banana-BANANA
BANANA-BANANA
mela-MELA
MELA-MELA
... while i am expecting:
pera^PERA~banana^BANANA~mela^MELA
pera-PERA
pera-PERA
banana-BANANA
banana-BANANA
mela-MELA
mela-MELA
can you help me please??