Function call within an associative array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FredEH
Forum Newbie
Posts: 18
Joined: Fri May 09, 2003 8:39 am

Function call within an associative array

Post 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 :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

would

Code: Select all

$array = array(
		"a" => $row[1],
		"b" => $row[2]
	);
$array['c'] =	function($array['a'], $array['b']);
);
be sufficient?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
FredEH
Forum Newbie
Posts: 18
Joined: Fri May 09, 2003 8:39 am

Post 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.
Post Reply