2012-12-05 60 views
1

我對我的腳本的以下部分有點困惑...在會話變量中的PHP動態數組

變量$ username和$ password來自POST表單並且沒問題。

session_start(); 

$errors = array(); 

if (empty($username) === true || empty($password) === true) { 
    $errors[] = 'You need to enter a username and password!'; 
    $_SESSION['Errors'] = $errors; 
} else if (user_exists($username) === false) { 
    $errors[] = 'We can\'t find the username! Have you registered?'; 
    $_SESSION['Errors'] = $errors; 
} else if (user_active($username) === false) { 
    $errors[] = 'You haven\'t activated your account!'; 
    $_SESSION['Errors'] = $errors; 
} 

當我試圖存儲任何$錯誤[]在會話變量,我在會話變量中找到的唯一價值就是「陣列」 ......

但是,當我寫的變量$錯誤(沒有[]),那麼它的工作原理...

我如何在這種情況下添加一個或多個動態堆棧的數組變量$ _SESSION ['Errors']?

這可能很簡單,但我在Internet上找不到任何解決方案。

非常感謝您提前。

回答

2

嘗試使用print_rvar_dump,因爲它是一個數組。使用echo只會產生Array

print_r($_SESSION['Errors']); //this 
var_dump($_SESSION['Errors']); //or this