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.
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:
Then call it like this: