Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 254011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:48:39+00:00 2026-05-11T21:48:39+00:00

To pass variables into functions, I do the following (as other people I’m sure):

  • 0

To pass variables into functions, I do the following (as other people I’m sure):

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

addNums(2, 2);

My question is how would I structure a function to act like WordPress:

wp_list_categories('title_li=');

Essentially I am looking for a way to create a key/value pair in my functions.
Any advice is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:48:40+00:00Added an answer on May 11, 2026 at 9:48 pm

    You can use parse_str to parse the string for arguments. The tricky thing is that you may not want to just allow any and all parameters to get passed in. So here’s an example of only allowing certain parameters to be used when they’re passed in.

    In the following example, only foo, bar and valid would be allowed.

    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 will be dropped because it is not listed in $valid_arguments. So for this call:

    print_r(exampleParseArgs('foo=20&bar=strike&baz=50'));
    

    Results:

    Array
    (
        [foo] => 20
        [bar] => strike
    )
    

    Additionally, you can browse the WordPress Source code here, and of course by downloading it from wordpress.org. Looks like they do something very similar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I pass a list of values into a function, where the values
Can you pass variables into subqueries, like so? SELECT users.id AS id, (SELECT SUM(total)
I'd like to pass some variables into my .nsi script. Either from the environment
I want to pass 2 variables: UIImage * img int i into another method
This question started out with me not understanding why I couldn't pass variables to
Developing a module for drupal and I need to pass/modify variables within functions. I
Is there a way to pass a variable into a regex in jQuery/Javascript? I
I am trying to pass a php variable into a java script window.location that
Is it possible to pass a search variable into the Google Custom Search Engine
How in the world do I pass a string variable into GQL with python??

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.