UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

46 lines (41 loc) 1.1 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://www.coursesweb.net" rel="nofollow">CoursesWeb</a> </strong> on 2012-04-30 18:08:28 <br /> Hi, This is a comment to correct the function posted below. That function has an error, it returns the last key, eaven the value not match. Sorry, here's the corrected version: <pre><code> function array_search(val, array) { if(typeof(array) === 'array' || typeof(array) === 'object') { var rekey; for(var indice in array) { if(array[indice] == val) { rekey = indice; break; } } return rekey; } } </code></pre> <hr /> <strong> <a href="http://www.coursesweb.net" rel="nofollow">CoursesWeb</a> </strong> on 2012-04-30 17:12:56 <br /> Hi, For a simple array_search function, without the third parameter, i use made this variant (works with array and objects: <pre><code> function array_search(val, array) { if(typeof(array) === 'array' || typeof(array) === 'object') { for(var indice in array) { if(array[indice] == val) break; } if(indice) return indice; } } </code></pre> <hr />