获取会话中数组的元素和值

get the elements and values of an array that is inside a session

我需要从另一个页面的会话中获取数组中的元素和值。

这是第一页

if (!$error) {
                session_start();
                $user_info = array
                (
                    'fullName' => $fullName,
                    'street_address' => $street_address,
                    'city' => $city,
                    'state' => $state,
                    'zip' => $zip,
                    'country' => $country,
                    'email' => $email,
                    'phone' => $phone,
                    'planName' => $planName,
                    'planPrice' => $planPrice
                );
                $_SESSION['user_info'] = $user_info;
                header("Location:?pid=18&pmh=3");
            }

这是我需要在此处获取值的第二页

 <?php
var_dump($_SESSION['user_info']);

$proDetails = array(
    "proName"=>"this is the pro name"
);

require_once 'payment-api/Twocheckout.php';

Twocheckout::privateKey('4D67BA12-CE09-4F1D-AB20-0133F24E3472');
Twocheckout::sellerId('901249656');
Twocheckout::sandbox(true);

try {
    $charge = Twocheckout_Charge::auth(array(
        "merchantOrderId" => "123",
        "token" => $_POST['token'],
        "currency" => 'USD',
        "total" => '10.00',
        "billingAddr" => array(
            "name" => $_SESSION["user-info"]["fullName"],
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'example@2co.com',
            "phoneNumber" => '555-555-5555'
        )
    ));

    if ($charge['response']['responseCode'] == 'APPROVED') {
        echo "Thanks for your Order!";
        echo "<h3>Return Parameters:</h3>";
        echo "<pre>";
        echo "His name" . $charge['response']['billingAddr']['name'];
        var_dump( $charge );
        echo "<br />";
        echo $proDetails['proName'];
        echo "</pre>";
    }
} catch (Twocheckout_Error $e) {
    print_r($e->getMessage());
}

现在如您所见,我需要用来自会话的值替换 'Testing Tester'

我尝试这样做"name" => $_SESSION["fullName"],但是没有成功。

这是 var_dump($_SESSION['user_info']);

的 var_dump

array(8) { ["fullName"]=> string(6) "Yousef" ["street_address"]=> string(11) "this is ass" ["city"]=> string(5) "Cairo" ["state"]=> string(8) "Bassteen" ["zip"]=> string(7) "2125454" ["country"]=> string(3) "EGY" ["email"]=> string(21) "johnef_sh@hotmail.com" ["phone"]=> string(11) "01224853582" } Thanks for your Order!

简单。 fullName 变量是数组的一部分,它作为变量存储在 SESSION 数组中。所以:

$_SESSION["user_info"]["fullName"]

设置变量:

"name" => $_SESSION["user_info"]["fullName"]

请记住,在 php 中 N 维数组是可能的(当然受限于您的硬件)。