Skip to content

Instantly share code, notes, and snippets.

@ozee31
ozee31 / in_array.js
Created August 7, 2014 14:46
Indique si une valeur appartient à un tableau
/**
* Checks if a value exists in an array
* @param {mixed} needle : The searched value
* @param {array} haystack : The array
* @return {bool}
*/
var in_array = (function (needle, haystack) {
return ( haystack.indexOf(needle) !== -1 );
});
@ozee31
ozee31 / array_unset.js
Last active June 18, 2020 11:20
Supprime des éléments d'un tableau
/**
* Remove all occurrences of a given value from an array
* @param {mixed} val : value to delete
*/
Array.prototype.unset = function(val){
var index;
while ( (index = this.indexOf(val)) !== -1 ) {
this.splice(index,1);
}
@ozee31
ozee31 / array_depth.php
Last active August 29, 2015 14:04
Array depth : profondeur d'un array
<?php
/**
* Returns the level of depth of an array
* @param array $array
* @param integer $level : do not use, just used for recursivity
* @return int : depth
*/
function array_depth($array, $level = 0) {
if ( ! $array )