Page 1 of 1

Function call within an associative array

Posted: Fri May 09, 2003 8:39 am
by FredEH
Hi,

I would really appreciate it if someone could help me with this.
Here's an example of what my code looks like:

Code: Select all

$array = array( 
        "a" => $rowї1], 
        "b" => $rowї2], 
        "c" => function($a,$b), 
);
I need to be able to call "function" with "a" and "b" as arguements. Since "a" and "b" are in the array, can this be done? If so, what is the proper syntax? If not, how would I go about doing this?

Thanks in advance :)

Posted: Fri May 09, 2003 8:44 am
by volka
would

Code: Select all

$array = array(
		"a" => $row[1],
		"b" => $row[2]
	);
$array['c'] =	function($array['a'], $array['b']);
);
be sufficient?

Posted: Fri May 09, 2003 8:47 am
by twigletmac
For the example you've given (and I appreciate it could be a simplified version of your code), you could also do:

Code: Select all

$array = array( 
        "a" => $row[1], 
        "b" => $row[2], 
        "c" => function($row[1], $row[2]), 
);
Mac

Posted: Fri May 09, 2003 10:46 am
by FredEH
Thanks for the replies. This might work, I'll try it when I get a chance.
volka wrote:would

Code: Select all

$array = array(
		"a" => $row[1],
		"b" => $row[2]
	);
$array['c'] =	function($array['a'], $array['b']);
);
be sufficient?

Code: Select all

$array = array( 
        "a" => $row[1], 
        "b" => $row[2], 
        "c" => function($row[1], $row[2]), 
);
This would work, but yes... this is a very simplified version.

Thanks for the help.