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 3304666
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:05:10+00:00 2026-05-17T21:05:10+00:00

I know it is possible to use optional arguments as follows: function doSomething($do, $something

  • 0

I know it is possible to use optional arguments as follows:

function doSomething($do, $something = "something") {

}

doSomething("do");
doSomething("do", "nothing");

But suppose you have the following situation:

function doSomething($do, $something = "something", $or = "or", $nothing = "nothing") {

}

doSomething("do", $or=>"and", $nothing=>"something");

So in the above line it would default $something to “something”, even though I am setting values for everything else. I know this is possible in .net – I use it all the time. But I need to do this in PHP if possible.

Can anyone tell me if this is possible? I am altering the Omnistar Affiliate program which I have integrated into Interspire Shopping Cart – so I want to keep a function working as normal for any places where I dont change the call to the function, but in one place (which I am extending) I want to specify additional parameters. I dont want to create another function unless I absolutely have to.

  • 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-17T21:05:11+00:00Added an answer on May 17, 2026 at 9:05 pm

    No, in PHP that is not possible as of writing. Use array arguments:

    function doSomething($arguments = array()) {
        // set defaults
        $arguments = array_merge(array(
            "argument" => "default value", 
        ), $arguments); 
    
        var_dump($arguments);
    }
    

    Example usage:

    doSomething(); // with all defaults, or:
    doSomething(array("argument" => "other value"));
    

    When changing an existing method:

    //function doSomething($bar, $baz) {
    function   doSomething($bar, $baz, $arguments = array()) {
        // $bar and $baz remain in place, old code works
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have multiple ellipsis arguments in an R function? A simplified
I know it's possible to use CSS to add page breaks to web pages,
Does anyone know if it's possible to use regex capture within Apache's DirectoryMatch directive?
Does anyone know if it's possible to not use the navigation properties feature of
I know it's possible, and I've seen simple examples in the documentation, but are
I know it's possible to use a grabbing cursor icon in Chrome (in Gmail,
I want to know if it is possible to use MySQL Engine without having
I know you can use python and other scripting languages in android. But I
I know its probably possible, but is it practical and doable to try and
I know its probably possible, but is it practical and doable to try and

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.