Skip to content

Instantly share code, notes, and snippets.

@harmlessprince
Created April 16, 2021 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmlessprince/03bb86d4d73c584728c5ec55c56961ca to your computer and use it in GitHub Desktop.
Save harmlessprince/03bb86d4d73c584728c5ec55c56961ca to your computer and use it in GitHub Desktop.
This filters out a given number out from an array and returns the new length of the array
<?php
function filter_val( array $arr, int $val) : int{
$output = array_filter($arr, function($value) use ($val) {
return $value - $val != 0;
});
return count($output);
}
$array = [5,2,2,5,3];
$val = 5;
print_r(filter_val($array, $val));
@harmlessprince
Copy link
Author

Well, Understood, I guess the type hinting doesn't help the average user much...

Thanks for the review, Really appreciate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment