Jump to content

validate an array has any > 0


turpentyne

Recommended Posts

This is probably a simple one, but I'm not experienced with arrays.

 

I have a form with looped dropdowns for items from a database. On submit it goes to a second page. Before I run any script I want to make sure the array created from the dropdowns contains anything greater than 0...

 

I thought this would do it:

 

if (isset($_POST['participantqty']) && ($_POST['participantqty']) > 0){

But it does nothing.

 

I also tried:

if (isset($_POST['participantqty[]']) && ($_POST['participantqty[]']) > 0){

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/257383-validate-an-array-has-any-0/
Share on other sites

max()

 

This will return the highest value in the array. But, you are referring to the field incorrectly

 

if (isset($_POST['participantqty']) && max($_POST['participantqty']) > 0){

 

You would likely need to do some additional validations based upon what you expect the values to be. If you don't want the '0' values int eh array you might consider running it through array_filter() first.

This is probably a simple one, but I'm not experienced with arrays.

 

I have a form with looped dropdowns for items from a database. On submit it goes to a second page. Before I run any script I want to make sure the array created from the dropdowns contains anything greater than 0...

 

I thought this would do it:

 

if (isset($_POST['participantqty']) && ($_POST['participantqty']) > 0){

But it does nothing.

 

I also tried:

if (isset($_POST['participantqty[]']) && ($_POST['participantqty[]']) > 0){

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.