- Version: 0.1
- Date: 2019-01-22
- Author:
- Status: Concept
- First Published at: Github gist
Today, in_array
just support if array contains elements, but isn't normalized into Array Functions. This RFC proposal new function normalized in Array Functions that count elements into array, that can used in both situations, check if element exists and count quantity of same element in array.
New function array_element_exists
, similar to in_array
, but organized on Array Functions and with count elements.
int|bool array_element_exists(mixed $var, array $array)
Count number of elements in array.
var
The value to check.
array
An array with elements to check.
Returns number of elements found in array, FALSE otherwise.
Example #1:
<?php
$array = array("a", "b", "c", "a", "b", "c", "a");
var_dump(array_element_exists("a", $array)); /// int(3)
var_dump(array_element_exists("b", $array)); // int(2)
var_dump(array_element_exists("d", $array)); // bool(false)
This RFC doesn't anything, this is new function.
The next PHP 7.x, current version 7.3.
This RFC has no impact on existing core, functions or extensions.
Is out of scope, but can be considered depreciate in_array
in the future.
- The name of function can be
array_element_count
insteadarray_element_exists
. - The function can return only int, with zero with no elements or number of elements found.