function array_diff_assoc ( array ) { // Computes the difference of arrays with additional index check // // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) var arr_dif = {}, i = 1, argc = arguments.length, argv = arguments, key, key_c, found=false; // input sanitation if( !array || (array.constructor !== Array && array.constructor !== Array && typeof array != 'object' && typeof array != 'array') ){ return null; } // loop through 1st array for ( key in array ){ // loop over other arrays for (i = 1; i< argc; i++){ // find in the compare array found = false; if(argv[i][key]){ found = true; break; } if(!found){ arr_dif[key] = array[key]; } } } return arr_dif; }
array_diff_assoc({0: 'Kevin', 1: 'van', 2: 'Zonneveld'}, {0: 'Kevin', 4: 'van', 5: 'Zonneveld'});
Дерево всех статей