I have a string that is formatted like this:
function1!!param1||ignore!!param2&&function2!!param1||ignore!!param2||ignore!!param3
The number of functions it has is unlimited (they are split with &&)
a basic function call that would be generated from the string above is:
function1($param1,$param2);
and the second one:
function2($param1,$param2,$param3);
the number of params is unlimited. (they aren't called function and param that is only an example)
Happy to answer any questions!! I already tried exploding by && and then !! but I can't quite figure out how to call a dynamic function with dynamic params.
Solution for 5.2:
function function1( $a1, $a2 ) {
echo $a1 . $a2;
}
function function2( $a1, $a2, $a3 ) {
echo " ".$a1 . $a2 . $a3;
}
function explodemap($val) {
$explode = explode( "!!", $val );
return $explode[1];
}
$functions = explode( "&&", 'function1!!param1||ignore!!param2&&function2!!param1||ignore!!param2||ignore!!param3' );
foreach( $functions as $function ) {
$split = explode( "||", $function );
$weird_excalmation_split = explode("!!", $split[0] );
$params = array_slice( $split, 1 );
$params = array_map( "explodemap", $params );
$fn_name = $weird_excalmation_split[0];
array_unshift( $params, $weird_excalmation_split[1] );
call_user_func_array( $fn_name, $params );
}