开发者

question in sessions and array

开发者 https://www.devze.com 2023-03-22 03:43 出处:网络
i have session code it\'s working fine but some friend told me this code should not work ! but it\'s work fine with me !

i have session code

it's working fine

but some friend told me this code should not work !

but it's work fine with me !

i try code on localhost

so my question is , if i uploaded this code to my server

it will work fine like localhost ?

or will not work like my friend said ?

my code is

session_start();
$_SESSION['news'][] = 'First';
$_SESSION['news'开发者_JAVA技巧][] = 'Second';
print_r($_SESSION['news']);

its print Array ( [0] => First [1] => Second )

and that's what i want ! it's fine ..


Yes it will work definitely. Or to be more safe you can do like following before assigning it values.

    $_SESSION['news'] = array();


Your friend is wrong. You can use arrays as session variables.

For supporting arguments, please see array as session variable and Can I Store An Array In A Session?.


It seems okay to me. There's no reason why it shouldn't work on your server.


After 5 hours of tests ,,

it's seems not work like my friend said !

he was right

for first time i used this way , i got an error

but i ingored it , because it's did not happin again !

but the error is show in first time only !

i browsed the page from another browser

i got that error !

i forget to save the error , but it's say you can not use empty []

after all , iam now use it as numbers

and thank you again and sorry for my language

0

精彩评论

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