开发者

PHP Sessions declaring 'Chinese' from the array

When i print_r my session i get:

Array ( [languages] => Array ( [0] => Chinese ) )

which is what i wanted.

And I have an if statement which is:

if($SES开发者_C百科SION == 'Chinese'){
        $_POST['languages'] = array('Chinese');

}

Which i think is 100% correct, but the problem I have is getting the if statement to compare to the correct part of the array. The If statement doesnt work though. I thought it maybe something like :

$session[0] but that doesnt work, could it im using the wrong parameter should i be using something other then ==, and ideas would be greatly appreciated


if($SESSION["languages"][0] == 'Chinese'){
        $_POST['languages'][] = "Chinese";

}

You can also do this...

$_POST['languages'] = $SESSION["languages"];

What you want is...

$languages = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Korean","German");
foreach($_SESSION["languages"] as $language){
    if(in_array($language, $languages)){
        $_POST["languages"][] = $language;  
    }
}


Perhaps:

if ($_SESSION['languages'][0] == 'Chinese') {
    $_POST['languages'] = array('Chinese');
}


You want:

if($_SESSION['languages'] == 'Chinese')

However what you don't want to do is assign values to the $_POST array. These values should only be populated from the client side(submitting form etc).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜