Hi guys can you show me how to manipulate multidimensional array both setter and getter of an array inside a class.
Perhaps a nice sample codes that i can observe.
Thanks in advance.
Hi guys can you show me how to manipulate multidimensional array both setter and getter of an array inside a class.
Perhaps a nice sample codes that i can observe.
Thanks in advance.
If this is the same issue as addressed in this recent thread of yours? If so, my suggestion that you should instead be using an array of objects instead of an array of arrays still stands.
If you still insist on using an array of arrays, then the first thing you need to determine is whether the top-level array index will be meaningful, i.e. it's not just an arbitrary number but represents something about that sub-array (database primary key, product ID, etc.), or if it will just be a sequential array index such as you get using the $myArray[] = array(1,2,3); syntax.
something like this?:
<?php
class vars
{
private var data;
public function __construct ( $data = false )
{
$this->data = array();
if ( is_array( $data ) )
{
$this->data = $data;
}
}
public function setVar ( $name, $value )
{
$this->data[$name] = $value;
}
public function getVar ( $name )
{
return $this->data[$name];
}
}
?>