-
-
Save DavidGoodwin/10023233 to your computer and use it in GitHub Desktop.
Revisions
-
DavidGoodwin revised this gist
Apr 7, 2014 . 1 changed file with 23 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,28 @@ <?php /* Original effort: https://gist.github.com/Daniel15/5991193 */ function last($arr) { eval('list(' . str_repeat(',', count($arr) - 1) . '$result) = $arr;'); return $result; } /* An interesting challenge - what about : */ $list = array('a' => 'fish', 'b' => 'sausage', '&c' => 'whal=asdasd!@£123e'); /** * Return the last element of an array AND it's associated key * @param array (e.g. [ 23, 4, 5, 'fish' => 'beans' ] etc.) * * @return array last element of the array (as [$key => $value]) */ function last_element($array) { $string = http_build_query($array); preg_match('/(&?([^&=]*)=([^&=]*))$/', $string, $matches); $key = urldecode($matches[2]); $value = urldecode($matches[3]); return array($key => $value); } var_dump(last_element($list)); -
Daniel15 revised this gist
Jul 14, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php function last($arr) { eval('list(' . str_repeat(',', count($arr) - 1) . '$result) = $arr;'); -
Daniel15 created this gist
Jul 13, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ function last($arr) { eval('list(' . str_repeat(',', count($arr) - 1) . '$result) = $arr;'); return $result; }