Hey guys I am trying to solve this type of a problem in PHP
Hey guys I am trying to solve this type of a problem in PHP
`write a function count items that recursively passes through all arrays and cunts the number of occurrences of a given item. keep in mind that array can be nested within each other
For example, ArraySearch::countItem($arr, 'apple') for the array below should return 2.
This is what I got so far
`write a function count items that recursively passes through all arrays and cunts the number of occurrences of a given item. keep in mind that array can be nested within each other
For example, ArraySearch::countItem($arr, 'apple') for the array below should return 2.
$arr = [
"apple",
["banana", "strawberry", "apple"]
];
This is what I got so far
<?php
class ArraySearch
{
public static function countItems($arr, $item)
{
return NULL;
}
}
$arr = [
"apple",
["banana", "strawberry", "apple"]
];
echo ArraySearch::countItems($arr, "apple");
No any search results
You already invited:
1 Answers
Paul Williamson
Upvotes from: Tom