Is it possible to pass arrays into a function and/or return an array from a function? I think it's possible but I don't really know how to go about it.
lets say I have a function that returns a bunch of field from a database
ex:
function a($sql){
$result = mysql_query($result);
/*should I do this...
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
return $row;
}*/
/*or this*/
$row = mysql_fetch_array($result, MYSQL_ASSOC)
return $row;
}
and how do I call a function if it returns an array? should I do something like this?
$get_stuff= a($query);
foreach($get_stuff as $get_stuffs){
//do stuff
}
and on another note... how do I handle an array after passing it to a function?
lets say I have something like this
$args=array('field1'=>'value',
'field2'=>'value');
$query = $get_query($args);
function $get_query($array){
foreach($array as $str){
//form a string that will be accepted into mysql.
}
return str;
}
The reason I'm asking all these questions is because I'm tired of manually writing code over and over again when getting data from mysql, so I'm trying to create a class that'll make it easier for me.
thanks to anyone who is willing to help!