note 107733 added to function.end
| From: | jorgeatREMOVETHIS-2upmediadotcom | Date: | Thu, 01 Mar 2012 01:20:48 +0000 |
| Subject: | note 107733 added to function.end | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186434@lists.php.net to get a copy of this message | ||
If all you want is the last item of the array without affecting the internal array pointer just do
the following:
<?php
function endc( $array ) { return end( $array ); }
$items = array( 'one', 'two', 'three' );
$lastItem = endc( $items ); // three
$current = current( $items ); // one
?>
This works because the parameter to the function is being sent as a copy, not as a reference to the
original variable.
----
Server IP: 208.69.120.55
Probable Submitter: 184.88.146.187
----
Manual Page -- http://www.php.net/manual/en/function.end.php
Edit -- https://master.php.net/note/edit/107733
Del: integrated -- https://master.php.net/note/delete/107733/integrated
Del: useless -- https://master.php.net/note/delete/107733/useless
Del: bad code -- https://master.php.net/note/delete/107733/bad+code
Del: spam -- https://master.php.net/note/delete/107733/spam
Del: non-english -- https://master.php.net/note/delete/107733/non-english
Del: in docs -- https://master.php.net/note/delete/107733/in+docs
Del: other reasons-- https://master.php.net/note/delete/107733
Reject -- https://master.php.net/note/reject/107733
Search -- https://master.php.net/manage/user-notes.php