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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:41:03+00:00 2026-05-23T12:41:03+00:00

I have the following PHP function: function func_name($name = ‘John’, $country = ‘USA’) {

  • 0

I have the following PHP function:

 function func_name($name = 'John', $country = 'USA')
  {
  do something;
  }

And now, am trying to pass variable to the function as follows:

func_name($name = 'Jack', $country = 'Brazil');

I know, we can pass it easily as func_name('jack', 'Brazil'); but the above function is just an example. The actual function has around 20 arguments and all have default values, and some are not at all passed to the function

So I would like to know if its proper to pass arguments as func_name($name = 'Jack', $country = 'Brazil');

  • 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-23T12:41:03+00:00Added an answer on May 23, 2026 at 12:41 pm

    No, it’s not the right way to do it. foo($bar = 'baz') means you’re assigning 'baz' to the variable $bar as usual. This assignment operation results in the value that was assigned, so the expression $bar = 'baz' has the value 'baz'. This value 'baz' gets passed into the function. The functions doesn’t have any clue that you have assigned to a variable $bar.

    In other words, PHP doesn’t support named arguments.

    If your function accepts many parameters, all or most of which are optional, use arrays:

    function foo(array $args = array()) {
        // set default values for arguments not supplied
        $args += array('name' => 'John', 'country' => 'USA', …);
    
        // use $args['name'] etc.
        // you could do extract($args), then use $name directly,
        // but take care not to overwrite other variables
    
    }
    
    foo(array('country' => 'Japan'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php function which i wrote a while ago. Now however,
Suppose we have following function in PHP: public function testSomething() { $name = perform_sql_query("SELECT
I have code with the following form: <?php function doSomething{ //Do stuff with MySQL
I have the following scenario jQuery('#content').fadeOut('slow',function(){ jQuery('#content').load(detail.php?product=+imgID+&category=+cat); jQuery('#content').fadeIn('fast'); }); My problem however is that
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following javascript: $('#ge-display').click(function (event) { window.open('/googleearth/ge-display.php','','scrollbars=yes,menubar=no,height=650,width=1000,resizable=yes,toolbar=yes,location=no,status=no'); event.stopPropagation(); return false; }); the
I have tried to do this refering to following link. http://skypher.com/index.php/2008/07/28/function-list-for-php/ But no success.
I added the following .htaccess rule:- RewriteRule ^widgets$ products.php?cat=20 [QSA] So now I have
I have the following PHP code; <?php component_customer_init(); component_customer_go(); function component_customer_init() { $customer =
I have the two following files: main.php include(functions.php) __EXTRACT(); echo $testvar; functions.php function __EXTRACT(){

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.