In order to have a form modeled, I would like to store the objects,
which represent the form fields in an array of the object representing
the form.
Nevertheless, the values of the objects in the array can be sometimes
accessed, sometimes not. Any explanations?
Here is a similar code:
<?php
class A {
//for example a form field
var $a;
function set_a($arg){
$this->a=$arg;
}//function
}//class
class B {
//for example a form
var $b=array();
}//class
/*
--here the script Output:
1: 1
2: 2
1:
2:
*/
$ob = new B;
$ob->a[1]=new A;
$ob->a[2]=new A;
foreach($ob->a as $index=>$value){
$value->set_a($index);
echo $index.': '.$value->a.'<br />' ;
}
foreach($ob->a as $index=>$value){
echo $index.': '.$value->a.'<br />' ;
}
?>