To pass through variables into functions, I actually do the next (as others I am sure):

function addNums($num1, $num2)
    $num1 + $num2;

addNums(2, 2);

My real question is wouldso would I structure a function to do something like Wordpress:


Basically I'm searching for a method to produce a key/value pair during my functions. Any advice is appreciated.

You should use parse_str to parse the string for arguments. The tricky factor is you might not wish to just allow every parameters to obtain passed in. So here's a good example of only permitting certain parameters for use when they are passed in.

Within the following example, only foo, bar and valid could be permitted.

function exampleParseArgs($arg_string) {
    // for every valid argument, include in
    // this array with "true" as a value
    $valid_arguments = array(
    	'foo' => true,
    	'bar' => true,
    	'valid' = true,
    // parse the string
    parse_str($arg_string, $parse_into);
    // return only the valid arguments
    return array_intersect_key($parse_into,$valid_arguments);


baz is going to be dropped since it is unlisted in $valid_arguments. So with this call:



    [foo] => 20
    [bar] => strike

Furthermore, you are able to see the Wordpress Source code here, not to mention by installing it from Appears like they are doing something much the same.

parse_str() must do what you would like: