Question:
PHP4 Specific
How can I dynamically creating a multi-dimensional array from multiple Class method calls?
Summary:
I have the following method in a class that creates an array from the three methods passed into the method:
function add_arg($arg_name = null, $arg_value = null, $arg_length = null) {
if(!(is_null($arg_name) || is_null($arg_value) || is_null($arg_length))){
$i = ++$this->_count_add_arg;
$numargs = func_num_args();
$arg_list = func_get_args();
$arg = array();
for($j=0; $j < $numargs; $j++){
array_push($arg, $arg_list[$j]);
}
}
}
When I call the method three times:
$o->add_arg("ARG1", '@', 1);
$o->add_arg("ARG2", '1', 1);
$o->add_arg("ARG3", '41', 2);
I get the following result of three seperate arrays:
[FONT=courier new]
Array ( [0] => ARG1 [1] => @ [2] => 1 )
Array ( [0] => ARG2 [1] => 1 [2] => 1 )
Array ( [0] => ARG3 [1] => 41 [2] => 2 )
[/FONT]
What I need to do next is put all three arrays into one (1) multi-dimensional array; such as:
Array (
[0] => Array (
[0] => ARG1
[1] => @
[2] => 1
)
[1] => Array (
[0] => ARG2
[1] => 1
[2] => 1
)
[2] => Array (
[0] => ARG3
[1] => 41
[2] => 2
)
)
I have tried to create a seperate method named [FONT=courier new]setArgs[/FONT] that uses the PHP method: array_map() and calling that within the method [FONT=courier new]add_arg[/FONT] noted above.
That doesn't work because it will get called three times...
If I try:
$o->setArgs();
Of course, that calls the method once. However, how do I get the three seperate arrays; created in the method [FONT=courier new]add_arg[/FONT] called three times; into the one method?
Isn't there a scope issue?
Any direction or help is greatly appreciated.
Thank you for reading this post.