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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:32:01+00:00 2026-06-04T03:32:01+00:00

Most of us know the following syntax: function funcName($param=’value’){ echo $param; } funcName(); Result:

  • 0

Most of us know the following syntax:

function funcName($param='value'){
    echo $param;
}
funcName();

Result: "value"

We were wondering how to pass default values for the ‘not last’ paramater? I know this terminology is way off, but a simple example would be:

function funcName($param1='value1',$param2='value2'){
    echo $param1."\n";
    echo $param2."\n";
}

How do we accomplsh the following:

funcName(---default value of param1---,'non default');

Result:

value1
not default

Hope this makes sense, we want to basically assume default values for the paramaters which are not last.

Thanks.

  • 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-06-04T03:32:04+00:00Added an answer on June 4, 2026 at 3:32 am

    PHP doesn’t support what you’re trying to do. The usual solution to this problem is to pass an array of arguments:

    function funcName($params = array())
    {
        $defaults = array( // the defaults will be overidden if set in $params
            'value1' => '1',
            'value2' => '2',
        );
    
        $params = array_merge($defaults, $params);
    
        echo $params['value1'] . ', ' . $params['value2'];
    }
    

    Example Usage:

    funcName(array('value1' => 'one'));                    // outputs: one, 2
    funcName(array('value2' => 'two'));                    // outputs: 1, two
    funcName(array('value1' => '1st', 'value2' => '2nd')); // outputs: 1st, 2nd
    funcName();                                            // outputs: 1, 2
    

    Using this, all arguments are optional. By passing an array of arguments, anything that is in the array will override the defaults. This is possible through the use of array_merge() which merges two arrays, overriding the first array with any duplicate elements in the second array.

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

Sidebar

Related Questions

Most of you probably know the following problem: You edit an HTML, view the
Most of the render function in the following view is irrelevant, I think but
I use EFCodefirst. Most of you know, but the following code is part of
To preface this, the most I know about text encoding I learned from Joel
I know that most people have DirectX9-capable cards but is it really necessary to
Most of us know that the command random.randint(1,n) in Python (2.X.X) would generate a
I know that most people say, OH! It's not possible, use php or whatever...
We all know that most applications out there assume class names to follow the
I already know that most implementations use a single thread, but is there anything
Python is the language I know the most, and strangely I still don't know

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.