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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:39:22+00:00 2026-05-26T23:39:22+00:00

I have a php file with different functions in it. I need to get

  • 0

I have a php file with different functions in it. I need to get data from strings in a function, but the strings have been specified in a different function. How can this be done please?

… To clarify, I have two functions.

function a($request) { $username = ...code to get username; } 

the username is over retreivable during function a.

function b($request) { } 

function b need the username, but cannot retrieve it at the point its called, so need it from function a. I am very much a beginer here (so bear with me please), I tried simply using $username in function b, but that didn’t work.

Can you please explain how I can do this more clearly please. There are another 5 strings like this, that function b needs from function a so I will need to do this for all the strings.

…Code:

    <?php
class function_passing_variables {

    function Settings() {       
        //function shown just for reference...
        $settings = array();
        $settings['users_data'] = array( "User Details", "description" );
        return $settings;
    }

    function a( $request ) {
        //This is the function that dynamically gets the user's details.
        $pparams = array();
        if ( !empty( $this->settings['users_details'] ) ) {
            $usersdetails = explode( "\n", Tool::RW( $this->settings['users_data'], $request ) );

            foreach ( $usersdetails as $chunk ) {
                $k = explode( '=', $chunk, 2 );
                $kk = trim( $k[0] );
                $pparams[$kk] = trim( $k[1] );
            }
        }

        $email=$pparams['data_email'];
        $name=$pparams['data_name'];
        $username=$pparams['data_username'];
       //These variables will retrieve the details
    }

    function b( $request ) {
        //Here is where I need the data from the variables
        //$email=$pparams['data_email'];
        //$name=$pparams['data_name'];
        //$username=$pparams['data_username'];
    }
}
?>
  • 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-26T23:39:23+00:00Added an answer on May 26, 2026 at 11:39 pm

    @A Smith, let me try to clarify what you mean.

    1. You have several variables, example : $var1, $var2, etc.
    2. You have two function (or more) and need to access that variables.

    If that what you mean, so this may will help you :

    global $var1,$var2;  
    
    function a($params){
    
       global $var1;
       $var1 = 1;
    }
    
    function b($params){  
    
       global $var1,$var2;
    
       if($var1 == 1){
          $var2 = 2;
       }
    }
    

    Just remember to define global whenever you want to access global scope variable accross function. You may READ THIS to make it clear.

    EDITED

    Now, its clear. Then you can do this :

    class function_passing_variables{
       // add these lines
       var $email = "";
       var $name = "";  
       var $username = "";  
      // ....  
    

    Then in your function a($request) change this :

    $email=$pparams['data_email'];
    $name=$pparams['data_name'];
    $username=$pparams['data_username'];
    

    to :

    $this->email=$pparams['data_email'];
    $this->name=$pparams['data_name'];
    $this->username=$pparams['data_username'];
    

    Now, you can access it in your function b($request) by this :

    echo $this->email;
    echo $this->name;
    echo $this->username;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP file with one simple echo function: echo 'アクセスは撥ねりません。'; but when
I have an index.php file which has to process many different file types. How
Do I have to put every file in a different folder? like: about-us/about-us.php profile/profile.php
I have a PHP file, Test.php, and it has two functions: <?php echo displayInfo();
I have a jquery script that collects data from different sites and saves it
i have a php file launching my exe. the exe does cout and the
I have a php file which I will be using as exclusively as an
I have a PHP file and an image in the same directory. How could
I have a PHP file which will return something like <div id=title>Add Us On
I have a PHP file that contains a lot of if and else statements

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.