如何扩大一个数组元素作为单独的参数传递给函数 [英] how to expand an array elements as separate parameters to a function

查看:106
本文介绍了如何扩大一个数组元素作为单独的参数传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有具有依赖于数据库的动态值颜色组成的数组。现在,这些值需要这需要值仅这样的功能('PARA1','PARA2','para3各个','para4')函数
 其中,参数1到param4是在阵列的颜色值。
问题是,我怎么可以解析这些值在上面的函数format.Only表示一个programminng逻辑required.Language是php。

I have an array of colors having dynamic values which depends on database. now these values are required in a function which takes values only like this function('para1','para2','para3','para4') where param1 to param4 are color values in an array. Problem is how can i parse these values to that function in the above stated format.Only a programminng logic required.Language is php.

假设动态数组是颜色[] =('红','栗色,蓝,绿);
而这些价值应该传递给这样的功能:setLineColor('红','栗色','蓝','绿色');

Suppose dynamic array is color[]=('red','maroon','blue','green'); and these value should be passed to this function like :setLineColor('red','maroon','blue','green');

我米使用此功能来创建图形(使用PHP_graphlib库。链接:的http:// www.ebrueggeman.com/phpgraphlib/documentation.php
任何其他建议的库welcomed.Plz提供与它的简单示例。

I m using this function for creating graphs.(Lib using PHP_graphlib: link: http://www.ebrueggeman.com/phpgraphlib/documentation.php) Any other suggested library is welcomed.Plz provide a simple example with it.

推荐答案

您可以使用该功能的 call_user_func_array

<?php
$colors = array('red','maroon','blue','green');
call_user_func_array('setLineColor', $colors);
?>

如果你想调用对象的方法,你可以用这个来代替:

If you want to call the method of an object, you can use this instead:

<?php
$graph = new ...
$colors = array('red','maroon','blue','green');
call_user_func_array(array($graph, 'setLineColor'), $colors);
?>

这篇关于如何扩大一个数组元素作为单独的参数传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆