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

  • Home
  • SEARCH
  • 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 6197437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:49:17+00:00 2026-05-24T03:49:17+00:00

Is there a way to make the arguments of a function act as an

  • 0

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"
);
  • 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-24T03:49:18+00:00Added an answer on May 24, 2026 at 3:49 am

    A function cannot take the argument as an array structure, so your best bet would be to use the method you specified in your second to last example:

    write(array(
        "key" => "value",
        "other_key" => "other_value"
    ));
    

    You could then have a default array within your function (if desired) so you could merge the two together so you always have a decent set of data.

    EDIT

    Unless you want to go crazy and pass it through as a string:

    write('
        "key" => "value",
        "other_key" => "other_value"
    ');
    

    And then parse that out on the other side… but IMO I wouldn’t bother, potentially opening yourself up to issues here.

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

Sidebar

Related Questions

Is there any way to make a function (the ones I'm thinking of are
Is there a way to pass an unlimited amount of arguments to a function,
In PHP is there a way to pass variable arguments as a single array
Is there a way to make this method properly generic and do away with
Is there a simple way to take the general arguments of a function (Pointer,
Is there a way to make a TSQL variable constant?
Is there a way to make a Radio Button enabled/disabled (not checked/unchecked) via CSS?
Is there a way to make a popup window maximised as soon as it
Is there a way to make running junit test to stop after a test
Is there a way to make a python module load a dll in my

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.