I’m trying to create clones of an element in an object and set new names for the clones.
class My_Obj{
var $obj;
var $obj_name;
var clone; //----int input to say how many clones are needed
var clone_names;//----array input to make clone's name different from $obj
function __construct( $args = '' ) {
$defaults=array(
/* codes to set up the default $obj */
)
if ( $this->clone >0 ){
for ( $i = 0; $i <= $this->clone; ++$i ){
$clone_obj[$i]['name'] = /* need to loop through array $clone_name to fill this */
}
}
/* other codes */
}
The $clone_names, for example, can be array(‘cat’, ‘dog’, ‘bird’). It doesn’t matter which order as long as each clone get a name. I would like to learn how to do this. Thanks!
If I understand your question correctly, you want to fill the array
$clone_objwith values from$clone_names– up to the number of clones specified in$clone?If that’s the case, this may work (I’ve rewritten the sample class you used):