Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php explode - needing second element

more out of interested...

$_GET['unique'] = blahblahblah=this_is_what_im_interested_in

I know I can get the second element like this:

$words = explode('=', $_GET['unique']);
echo $words[1];

Is there a way to get this in a single line? - that would then 'hopefully' allow me to add that to function/object call:

$common->resetPasswordReply(... in here I would put it....);

like

$common->resetPasswordReply(explode('=', $_GET['unique'])[1]);

I'm just interested to see if this is possible.

like image 922
Adam Avatar asked Dec 26 '22 02:12

Adam


2 Answers

PHP supports the indexing on functions if they are returning arrays/objects; so the following would work too:

echo explode('=', $_GET['unique'])[1];

EDIT

This is termed as array dereferencing and has been covered in PHP documentations:

As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable.

As of PHP 5.5 it is possible to array dereference an array literal.

like image 122
hjpotter92 Avatar answered Dec 29 '22 03:12

hjpotter92


This should do it for you.

substr($str, strpos($str, "=")+1);
like image 32
Orangepill Avatar answered Dec 29 '22 02:12

Orangepill