I am trying to get the number of times an element of an array meets a condition.
The situation is the following: I need to know how many elements of my array meet a condition.
I have my arrangement like this:
Array
(
[0] => 1
[1] => 97
[2] => 9
[3] => sin
)
Array
(
[0] => 1
[1] => 97
[2] => 9
[3] => sin
)
Array
(
[0] => 1
[1] => 97
[2] => 9
[3] => con
)
Here I need to know the following: how many elements have the value without and how many elements have the value with .
I need this to execute the following: when there are 6 or more elements with the value "without" I must make a discount. If there are 12 or more I must make another type of discount.
The truth is that I can't count the elements that meet that condition. I haven't tried much as I can't come up with anything good so far.
One other way to do this would be with recursive iterators , assuming that what you have is an associative array.
Departure:
First the array you have looks like the result of an array print, I would think your original array is:
To know what element is in the array, you have to go through it: