문제

I try to explode the session variable named "Name" to get only the first name of the user.

However, when I try to echo it, the result is always "Array".

$_SESSION['name'] = $row['Name'];
echo explode(" ", $_SESSION['name']);

Result is: Array

I even tried to store the $_SESSION['Name'] in a variable and explode that variable instead and got the same result.

Any idea? Thanks!

도움이 되었습니까?

해결책 2

You want

$tempVar = explode(" ", $_SESSION['name']);
echo $tempVar[0];

다른 팁

explode() returns an array. You need to access it by index or assign them to individual variables:

$names = explode(" ", $_SESSION['name']);
echo $names[0];

Or:

list($first, $last) = explode(" ", $_SESSION['name']);
echo $first;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top