开发者

Displaying $_SESSION['name'] and $_SESSION['surname']

开发者 https://www.devze.com 2023-03-30 14:37 出处:网络
I am just trying to display name and surname by session. But,they returned 0. 开发者_如何学CI don\'t understand why it returned 0 even though both of them are string. There is nothing interesting with

I am just trying to display name and surname by session. But,they returned 0. 开发者_如何学CI don't understand why it returned 0 even though both of them are string. There is nothing interesting with the codes;

<?php 

    echo   $_SESSION['name']+ ""+$_SESSION['surname'];

?>


The period (.) is the string concatenation operator in PHP.

By using the addition operator (+), you are coercing the operands to numbers, of which their value is 0. And obviously, 0 + 0 + 0 = 0.

What you want is...

echo $_SESSION['name'] . $_SESSION['surname'];

I removed the empty string in the middle because it won't do anything. Perhaps you meant a space?


echo $_SESSION['name'] ." ". $_SESSION['surname'];

Output will be like Name Surname for example : Mohit Bumb.

0

精彩评论

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