UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

81 lines (64 loc) 1.92 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-05-31 14:45:30 <br /> @ Martijn Wieringa: Nice! Thanks for taking the time to test it and write wrappers as well! <hr /> <strong> Martijn Wieringa </strong> on 2008-05-30 13:07:13 <br /> It turns out that 'shift' and 'unshift' functions are supported by JS itself (tested in IE 6 and FF 2) <pre><code> function array_shift(f_array) { if(f_array.length &gt; 0) { return f_array.shift(); } return null; } function array_unshift(f_array) { for(var i = 1; i &lt; array_unshift.arguments.length; i++) { f_array.unshift(array_unshift.arguments[i]); } return (array_unshift.arguments.length - 1); }</code></pre> <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-05-21 18:47:51 <br /> @ Buzz: I do not agree. The original array is changed by reference. But the function should return what has been removed: the value of the first element. <hr /> <strong> Buzz </strong> on 2008-05-21 17:13:47 <br /> array_shift(['Kevin', 'van', 'Zonneveld']); should return array('van','Zonneveld'); 3178 <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-04-07 11:30:29 <br /> @ Post cannot have an empty name: I agree that this function could probably be trimmed down a bit, but your version does not support associative arrays, so for now I'm going to have to stick with the current version. Do you agree? Thanks for your input, and if you have a different opinion or code, let me know! <hr /> <strong> Post cannot have an empty name </strong> on 2008-04-07 06:41:09 <br /> <pre><code> function array_shift(array) { element = array[0]; array.shift(array); return element; } </code></pre> <hr />