You are here: Passing variable number of arguments from array to function with call_user_func()? « PHP Programming Language « IT news, forums, messages
Passing variable number of arguments from array to function with call_user_func()?

Posted by rob on 08/13/07 00:42

Hello,

If I have an array made up of a bunch of key => value pairs, how can I
pass the values of each key as an argument to a function, given that
the number of items in the array are not static (i.e: sometimes
there's one item, sometimes there's two)?

For example, if I have the following array:

$list = array('sky' => 'blue', 'grass' => 'green');
$list = array_values($list);

I'd like to pass the two values in $list to a function that has two
arguments, i.e:

function color($sky, $grass) { }

The trick is is that $list will not always contain two items -
sometimes one, three, four, etc, so it has to pass them dynamically to
the function. I know about call_user_func(), and how I can pass
parameters to it, but I'm having a difficult time trying to pass
multiple parameters given that I don't know how many I need to pass.

Can anyone help?

Rob

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация