Is there a way to make the arguments of a function act as an array? I'm finding this difficult to explain.
Here's kind of an example.. When you declare an array, you can define the keys => values
like so:
$array = array(
"key" => "value",
"other_key" => "other_value"
);
And if I make a function that for an example outputs these onto the document, I could have:
function write($ar)
{
foreach($ar as $key => $value)
echo "$key: $value<br />";
}
write($array); // parse previously mentioned array
What I want to be able to do is omit the need to parse an array like above or below examples..
write(array(
"key" => "value",
"other_key" => "other_value"
));
I know I can use func_get_args()
to list any amount of arguments, but is there a similar function that lets you parse key => value
pairs rather than just a list of values?
Hope I described this in a way that makes sense, what I essentially want to end up with is something like:
write(
"key" => "value",
"other_key" => "other_value"
);