I have the following code:
$data = unserialize(db::select_xf_session_blob($_COOKIE['xf_session']));
$user_id = $data['user_id'];
It seems like a waste to have to declare a variable just so I can take the index of it.
This seems like a more elegant solution:
$user_id = unserialize(db::select_xf_session_blob($_COOKIE['xf_session']))['user_id'];
But it’s not valid, of course.
My question is, is there a more elegant way of writing my first code example?
In PHP 5.4 you can do the second one. But in the previous versions you have to do the first one.