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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:30:02+00:00 2026-05-25T15:30:02+00:00

Lets say we have function that gets 5 variables. function func($var1, $var2, $var3, $var4,

  • 0

Lets say we have function that gets 5 variables.

function func($var1, $var2, $var3, $var4, $var5 ) 
{
  if ($var1==1)
  {
    work with $var2, $var3
  }
  if ($var1==2)
  {
    work with $var4, $var5
  }
}

For example, we want to call this function like that: func(1,$var2, $var3) (without unused variables) or like that func(2,$var4, $var5).

Is it possible? How to send exact variables to php function?

UPDATE
Based on @marcus’s answer I modified my function.

<?

function GenerateTopNav($current, $lang, $db)
{
    $result=$db->query("SELECT `id`, `parent`, $lang FROM `nav` WHERE `menu`='1'");
        while ($row=$result->fetch_object()){
            echo '<a ';
            if($row->id==$current)
            echo 'class="active"';
            echo 'href="index.php?id='.$row->id.'">'.$row->$lang.'</a> | ';
    }

function GenerateLeftNav($parent, $level, $lang, $db){  
         $q = $db->query("SELECT `id`, `$lang` AS name FROM nav WHERE parent = '$parent' AND `menu`='2'");
          if($level > 0 && $q->num_rows > 0){
          echo "\n<ul>\n";
          }
          while($row=$q->fetch_object()){
                echo "<li>";
                echo '<a href="?page=' . $row->id . '">' . $row->name . '</a>';
                //display this level's children
                GenerateLeftNav($row->id, $level+1, $lang, $db);
                echo "</li>\n\n";
            }
          if($level > 0 &&  $q->num_rows > 0){
                echo "</ul>\n";
            }
          }
}
?>
  • 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-25T15:30:02+00:00Added an answer on May 25, 2026 at 3:30 pm

    Why do you even need to specify 4 variables? You’re basically saying specify a type and then 2 input variables for that type, so if there will always be 3 variables, just do the follow:

    function ($type, $var1, $var2) {
        if ($type === 1) {
            // $var1 = lang and $var2 = current
            // do something with var1 and var2
        } else {
            // $var1 = parent and $var2 = level
            // do something else with var1 and var2
        }
    }
    

    You really don’t need to spam your function with an excess number of variables that won’t get used.

    To be more clear: the variables don’t need to be named appropriately, you just need to comment that if type = 1, these two variables mean these two things, and if type = 2, these two variables mean these two things and process both types accordingly.

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

Sidebar

Related Questions

I have a class that has a function, lets say class.php: class fun {
Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
Let's say that I have an Erlang function, with spec. -spec foo(integer(), string()) ->
Lets say I have a function where the parameter is passed by value instead
Lets say I have a function f[x_, y_] , and two lists l1 ,
Let's say I have a program(C++, for example) that allocates multiple objects, never bigger
Lets say I have the following code that returns number of anchor elements on
Let's say we have a function that changes a password for a user in
How would you handle grouping different objects? For example, lets say you have a
Lets say I have a class like this in Java: public class Function {

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.