Remove element without loop CODE
// The array_diff() function compares the values of two (or more) arrays, and returns the differences. // Input: nums = [0,1,2,2,3,0,4,2], val = 2 // output: nums = [0,1,3,0,4]
function removeElement($nums, $val) {
    return array_diff($nums, [$val]);   
}
print_r(removeElement([0,1,2,2,3,0,4,2], 2);
// runtime 7ms
by Luka Khitaridze
2 years ago
PHP
Array
0
Pro tip: use ```triple backticks around text``` to write in code fences