Yair Villar
Yair Villar

Reputation: 195

if var == array then

I have an array with ids

$audit_answer_ids = array(85, 86);

now I have a foreach

$filtered_audits = array();
    foreach ($audits as $audit) {
      if (condition) {
        # code...
      }
      $filtered_audits[] = $audit;
    }

in the if (condition) I need to be able to do

$audit['Adusitoria']['id'] != $audit_answer_ids

so that way the system checks if $audit['Adusitoria']['id'] is equal to any of the ids in the array. Will just a simple if do?

Upvotes: 0

Views: 68

Answers (2)

Seth
Seth

Reputation: 317

Use the in_array function:

if( !in_array( $audit['Adusitoria']['id'], $audit_answer_ids )) {
}

Upvotes: 2

Fabio
Fabio

Reputation: 23510

I assume you already have $audit['Adusitoria']['id'] variable stored.
i was thinking to loop inside the array and then comparing

Code

$audit_answer_ids = array(85, 86);

foreach ($audit_answer_ids as $data) {
    if ($audit['Adusitoria']['id'] != $data) {
        //do something
    } else {
        //do something else
    }   
}

Upvotes: 1

Related Questions