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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:36:19+00:00 2026-06-17T11:36:19+00:00

Arrays created in function test(). Then I would like print their on page test.php

  • 0

Arrays created in function test().

Then I would like print their on page test.php.

My code down:

conf.php

function test(){
$str= array(
        'items' => array(
                0 => array(
                        'title' => 'Title',
                        'category' => 'Category name',
                        ),
                1 => array(
                        'title' => 'Title',
                        'category' => 'Category name',
                        ),
        ),
        'details' => array(
                'firstname' => 'firstname',
                'lastname' => 'lastname',
        ),
        'Id' => $Id,
        'OrderId' => 'fsdfsfdsrew'
);


$json = json_encode($str);
$base64 = base64_encode($json);

$sig = signMessage($base64, $secretPhrase);
}

test.php

require_once("conf.php");

test();
print_r($str);
print_r($json);
print_r($base64);
print_r($sig);

Tell me please why code not worked?

Tell me please why weren’t printed $str, $json, $base64, and $sig?

How do it?

Preferably without global parameters.

  • 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-17T11:36:20+00:00Added an answer on June 17, 2026 at 11:36 am

    You can’t without returning them as the function return value. In PHP, variables declared in a function (the arrays you’re trying to print_r in this case) are only available within the scope of that function unless you declare them global with the global keyword.

    Here’s the details on variable scope in PHP: http://php.net/manual/en/language.variables.scope.php

    You could construct a larger array to contain these arrays and return them from the test() function:

     function test(){
         //function code here....
         ////...
    
         $results = array('str'=> $str, 
                          'json'=> $json, 
                          'base64'=>$base64, 
                          'sig' => signMessage($base64, $secretPhrase)
                      ) ;
    
          return $results;
      }
    

    Then call it like this:

      $results = test();
      print_r($results['str']);
      print_r($results['sjson']);
      print_r($results['base64']);
      print_r($results['sig']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created and filled a multidimentional array, and passed it to a function, like
I created the following interface: <?php interface Action { public function execute(\requests\Request $request, array
I have a cell array of anonymous function handles, and would like to create
I would like to access the name field from the array items and print
I've created an EE plugin with a function that returns an array. e.g. function
I'm trying to create a function that would dynamically allocate an array, sets the
I am trying to make a small test function that when passed a char
I really like Backbone, but I am having the hardest time doing what would
As service provider has given me the following php code, which I need to
This is simple test on AS3 for BitmapData memory allocation. private function memoryTest(): void

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.