I got the idea when helping here: http://www.phpfreaks.com/forums/index.php/topic,267209.0.html
I've created this very sketchy function for pushing string variables into a function:
(hopefully you can see how it works)
<?php
function arg_splitter($input,$arg_count=false,$args_num='args_num') {
$split = preg_replace('/\$|\"/','', preg_split('/\"[\s,]+\$/',$input));
/* First this splits the inputted string on any number of commas
* or spaces inbetween the characters " and $
* then it replaces all $ and " characters with nothing
* my regex skillz suck.
*/
foreach ($split as $key=>$val) {
$split[$key] = explode("=",$val);
$assocarray[$split[$key][0]] = $split[$key][1]; //creates associative array so you can use extract on it
}
if($arg_count) {
$assocarray[$args_num]=count($assocarray);
}
return $assocarray;
}
function newfn($inputs) {
extract(arg_splitter($inputs,true,'arg_count')); // Only line needed to be added
if(isset($override) && !is_null($override)) {
echo "O MAYN, WE GOT OVERRIDDEN!!!!\n<br />";
echo "\$override = $override\n<br />";
return;
}
echo "\$a = $a\n<br />";
echo "\$b = $b\n<br />";
echo "\$c = $c\n<br />";
echo "\$d = $d\n<br />";
echo "\$arg_count = $arg_count\n<br /><br />";
}
echo "Test 1: \n<br />";
newfn('$a="apple",$b="banana", $c="carrot",$d="date"');
echo "Test 2: \n<br />";
newfn('$override="apple, banana, carrot, duck"');
?>
gives an output of:
Test 1:
$a = apple
$b = banana
$c = carrot
$d = date
$arg_count = 4
Test 2:
O MAYN, WE GOT OVERRIDDEN!!!!
$override = apple, banana, carrot, duck
Any easier/other way of doing this?
thanks