rashmi_k28 Posted October 23, 2008 Share Posted October 23, 2008 Hi, I have a array of $param and how to pass the values of $param to groupValues() function. $param=array('bw','pkt','cpu'); $values = groupValues(); function groupValues(){ $value = array(); $sql = "select field1 from tabe1"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $value['pkt'][] = $row[0]; } $sql = "select field2 from tabe2"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $value['bw'][] = $row[0]; } $sql = "select field3 from tabe3"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $value['cpu'][] = $row[0]; } $sql = "select field4 from tabe4"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $value['mem'][] = $row[0]; } $sql = "select field5 from tabe5"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $value['vmem'][] = $row[0]; } return $value; } There are many queries inside the function. How to query the function based on the array $param values passed to the function. Link to comment https://forums.phpfreaks.com/topic/129749-argument/ Share on other sites More sharing options...
GKWelding Posted October 23, 2008 Share Posted October 23, 2008 Just modify this to fit your code... $param = ('array1','array2','array3'); foreach($param as $value){ handleArray($value); } function handleArray($value){ if($value=="array1"){ QUERY FOR ARRAY1; }elseif($value=="array2"){ QUERY FOR ARRAY2; }elseif($value=="array3"){ QUERY FOR ARRAY3; }else{ echo "ERROR"; } } Link to comment https://forums.phpfreaks.com/topic/129749-argument/#findComment-672679 Share on other sites More sharing options...
.josh Posted October 23, 2008 Share Posted October 23, 2008 Just pass the array as an argument... $array = array (1,2,3,4,5); function something($array) { print_r($array); } something($array); Link to comment https://forums.phpfreaks.com/topic/129749-argument/#findComment-672685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.