diff --git a/solution/1400-1499/1426.Counting Elements/README.md b/solution/1400-1499/1426.Counting Elements/README.md index 90f2d1b697d42..ec6a0ece881f6 100644 --- a/solution/1400-1499/1426.Counting Elements/README.md +++ b/solution/1400-1499/1426.Counting Elements/README.md @@ -213,6 +213,24 @@ var countElements = function (arr) { }; ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function countElements($arr) { + $cnt = 0; + for ($i = 0; $i < count($arr); $i++) { + if (in_array($arr[$i] + 1, $arr)) $cnt++; + } + return $cnt++; + } +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1426.Counting Elements/README_EN.md b/solution/1400-1499/1426.Counting Elements/README_EN.md index 18f80783e2921..f507a2b3659b6 100644 --- a/solution/1400-1499/1426.Counting Elements/README_EN.md +++ b/solution/1400-1499/1426.Counting Elements/README_EN.md @@ -190,6 +190,24 @@ var countElements = function (arr) { }; ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function countElements($arr) { + $cnt = 0; + for ($i = 0; $i < count($arr); $i++) { + if (in_array($arr[$i] + 1, $arr)) $cnt++; + } + return $cnt++; + } +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1426.Counting Elements/Solution.php b/solution/1400-1499/1426.Counting Elements/Solution.php new file mode 100644 index 0000000000000..047793b09fdda --- /dev/null +++ b/solution/1400-1499/1426.Counting Elements/Solution.php @@ -0,0 +1,13 @@ +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function countElements($arr) { + $cnt = 0; + for ($i = 0; $i < count($arr); $i++) { + if (in_array($arr[$i] + 1, $arr)) $cnt++; + } + return $cnt++; + } +} \ No newline at end of file