I have a form that sends integers up to $_POST['ore'] from a table of select boxes and text input fields. Array in question is:
print_r($_POST)
//returns
Array
(
[ore] => Array
(
[0] => 1
[1] => 2
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
)
....
And that's all the bigger it gets, it's a small application. 10 select boxes, 10 input boxes. The form itself and the other functions work great.
However, On submit the data is sent to another page that processes the information gathered and generates a new table with a while loop based on the count of that array. But, I only want to count the values that are greater than 0 as zero is technically empty.
I have tried multiple functions, examples, bits pieces and tried dumb luck too but no positive results. I have gotten some to work partially, but most of the time they leave out the last row.
I currently have size = count($_POST['ore']); - however this creates a table with 10 rows (as it should) and fills the rest of the rows in the table with the last loop of the while code. Functional, but annoying and not what I would like to do.
I have tried array_filter with
function nonzero($var){
return ($var > 0); }
$size = array_filter($_POST['ore'], "nonzero");
No luck.
I have tried if(isset($_POST['ore'])) in multiple places, but since there is a 0 value in the array, it's technically set.
So, how do I count ,or filter then count, the $_POST['ore'] array values to strip away the 0's and only count or return the keys that are greater than 0?
My beat up keyboard and I thank you in advance.
Edit - Found the answer thank you all for the feedback this early in the morning
function nonzero($var){
return ($var > 0); }
$size = count(array_filter($_POST['ore'], "nonzero"));
^^ that did it