PageRenderTime 140ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/functions/array/array_walk_recursive.js

http://github.com/kvz/phpjs
JavaScript | 27 lines | 17 code | 4 blank | 6 comment | 8 complexity | 040b704680bb317fe81c0ceb68509bde MD5 | raw file
  1. function array_walk_recursive (array, funcname, userdata) {
  2. // http://kevin.vanzonneveld.net
  3. // + original by: Johnny Mast (http://www.phpvrouwen.nl)
  4. // * example 1: array_walk_recursive ({'a': 'b', 'c': {'d': 'e'}}, 'void', 'userdata');
  5. // * returns 1: true
  6. // * example 2: array_walk_recursive ('a', 'void', 'userdata');
  7. // * returns 2: false
  8. var key;
  9. if (typeof array != 'object') {
  10. return false;
  11. }
  12. for (key in array) {
  13. if (typeof array[key] == 'object') {
  14. return this.array_walk_recursive(array[key], funcname, userdata);
  15. }
  16. if (typeof(userdata) != 'undefined') {
  17. eval(funcname + '( array [key] , key , userdata )');
  18. } else {
  19. eval(funcname + '( userdata ) ');
  20. }
  21. }
  22. return true;
  23. }