Rixhers Ajazi
Rixhers Ajazi

Reputation: 1313

Checking if value in array is greater then a number

I am working on a HTML email, I need to attach forms, but attach forms that have a value less then or equal to 37 (<= 37)

I think I sorta figured out my problem that I am having with this piece of code :

           if ($this->input->post('form') <= 37) {
              ...........................................
            }

What I think this is searching for is if the array form[] actually has 37 keys in it not the if the value is less then or equal to 37.

What I want is to see if the array form has values less then if it does attach those forms, then the next thing I want to check is if the array form has a value >= 38 then attach the next set of forms.

This is what I have tried :

            if ($this->input->post('form') <= 37) {
                // Attach all the forms with a value of less then or equal to 37
            }
            if ($this->input->post('form') >= 38) {
               //Attach all the forms with a value of greater then or equal to 38
            }

Is this possible?

Edit 1

Just to clear up my question the problem I was/am having is that I want to check if the values in my form[] array are less then or equal to 37, if they are attach all forms with ID less then or to 37. If they are not then attach all the forms with ID greater then or equal to 38. Hopefully this clears up the question.

Edit 2

Thanks to the help of okok with his tip on how to get the value quite simple, I just wasn't even thinking of doing anything like that. Good job okok

here is the snippet of code that does the emailing if any one is interested!

Upvotes: 1

Views: 1471

Answers (1)

Filippo oretti
Filippo oretti

Reputation: 49813

your question is bit unclear, anyway, to check values > < or = do this

    if(is_array($this->input->post('form')) && count($this->input->post('form')) > 0){
       foreach($this->input->post('form') as $value){
        if($value > 37){
        //do somenthing
        }
         if($value <= 38){
        //do somenthing
        }

         //etc ..
        }
    }

to check how many keys the array has do this:

if(count($this->input->post('form')) > 37){

}
if(count($this->input->post('form')) <= 38){

}

Upvotes: 1

Related Questions