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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:58:00+00:00 2026-05-24T10:58:00+00:00

Hello and thanks for being there, I would like to pass a variable (

  • 0

Hello and thanks for being there,

I would like to pass a variable ($user) from a previous function to another one, but I need to use the arguments of the new function to pass the values that will render this new one.

Is there any way I can pass a variable from another function to a new function that only expects three arguments, and none of them is the variable from the previous function?

Example:

function my_function($country, $age, $colour) {
  if ($user = true) {
    echo "User is from " . $country . " and " . $age . " and his favourite colour is " . $colour; 
  }
}

my_function("italy", 19, "red");

It works if I put inside function my_function:

global $user;

but I believe using global variables is not a good practice.

Any idea on how to pass it as an argument? Should I just add it as another variable after $colour in the arguments of the new function?

Thanks a lot for your help 🙂

  • 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-24T10:58:01+00:00Added an answer on May 24, 2026 at 10:58 am

    You can pass it as an argument, or better do this:

    if ($user) my_function("italy", 19, "red");
    

    since you don’t have to use the $user variable inside that function.

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

Sidebar

Related Questions

Basically, I have one div(divNew) which is being populated with content from another page(thread.php)
I have a program whereby Data is being sent from one computer to another
I would like to be able to extract a number from within a string
Hello everyone and thank you for your time. I would just like to say
Hello How would one go about reverse engineering a page such as the this
Hello and thanks for your opinion. I am creating a webservice. This webservice will
Hello and thanks to everyone for reading my question. I've been working on a
Hello (and thanks in advance) I'm in a bit of a quandry, I cant
I have this kinda template text : Hello {#Name#}, Thanks for coming blah on
Suppose file1 looks like this: bye bye hello thank you And file2 looks like

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.