jeudi 19 décembre 2019

"IF" condition to compare two arrays in PHP

I have two array

$array1 = array(25) {
  ["ID"]=>
  int(508)
  ["label"]=>
  string(8) "Document"
  ["value"]=>
  array(1) {
    [0]=>
    object(WP_Term)#11926 (10) {
      ["term_id"]=>
      int(25)
      ["name"]=>
      string(6) "note 1"
      ["slug"]=>
      string(6) "note-1"
             }
           }
  ["menu_order"]=>
  int(0)
...
}

$array2 = array(25) {
  ["ID"]=>
  int(526)
  ["label"]=>
  string(10) "Document 2"
  ["value"]=>
  array(2) {
    [0]=>
    array(2) {
      ["value"]=>
      string(5) "#link"
      ["label"]=>
      string(4) "link"
    }
    [1]=>
    array(2) {
      ["value"]=>
      string(5) "#link"
      ["label"]=>
      string(4) "link"
    }
  }
...
}

I would like to create an IF condition - if the array contains "object (WP_Term)" then print "correct".

I try:

if(in_array('object', $array1)) {
print 'correct';}

Unfortunately it does not work. Please help me create the condition. thx

Aucun commentaire:

Enregistrer un commentaire