0

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?

1

2 Answers 2

2

Use the in_array function:

if( !in_array( $audit['Adusitoria']['id'], $audit_answer_ids )) {
}
Sign up to request clarification or add additional context in comments.

Comments

1

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
    }   
}

1 Comment

thanks for your answer but the best way to do it is with the in array, thanks anywais :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.