You are not logged in.
Login
or
Register
.
JsPHP: a JavaScript library providing the PHP API
Home
Register
Demo
Categories
Functions
Contributors
Download
Links
Comments
FAQ
Contact
View
Edit
Benchmark
Revisions
Developers
Dependencies
Talk
Links
reset:
Edit: reset
Function:
reset
View reset
Edit reset
Edit code
Edit tests
Edit benchmark
View latest code
Edit latest code
Benchmark reset
Comment on reset
Comment on the latest code
View revisions
View versions
View contributors
View dependencies
View comments
View links
Download production code
Download development code
View the PHP docs
View phpjs.org
View phpjs.org raw code
Description:
Set array argument's internal pointer to the first element and return it.
Edit function
Code
:
function reset (arr) { // http://jsphp.co/jsphp/fn/view/reset // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Legaev Andrey // + revised by: Brett Zamir (http://brett-zamir.me) // % note 1: Uses global: php_js to store the array pointer // * example 1: reset({0: 'Kevin', 1: 'van', 2: 'Zonneveld'}); // * returns 1: 'Kevin' // BEGIN REDUNDANT this.php_js = this.php_js || {}; this.php_js.pointers = this.php_js.pointers || []; var indexOf = function (value) { for (var i = 0, length = this.length; i < length; i++) { if (this[i] === value) { return i; } } return -1; }; // END REDUNDANT var pointers = this.php_js.pointers; if (!pointers.indexOf) { pointers.indexOf = indexOf; } if (pointers.indexOf(arr) === -1) { pointers.push(arr, 0); } var arrpos = pointers.indexOf(arr); if (Object.prototype.toString.call(arr) !== '[object Array]') { for (var k in arr) { if (pointers.indexOf(arr) === -1) { pointers.push(arr, 0); } else { pointers[arrpos + 1] = 0; } return arr[k]; } return false; // Empty } if (arr.length === 0) { return false; } pointers[arrpos + 1] = 0; return arr[pointers[arrpos + 1]]; }
You have to be logged in to edit functions.
Edit tests
Code
:
You have to be logged in to edit tests.
Edit benchmark
Code
:
You have to be logged in to edit benchmarks.
[
top
]
Comments
There are no comments yet, be the first!
Please
Login
or
Register
to post comments.