Build array and compare two foreach and wp_update_post on non-matching IDs

So I’m somewhat confused and need some assistance from the community, so I have a piece of code that I’m working on and I would like to compare two arrays and then if IDs don’t match, to put the post in pending state.

I have the following method:

/**  * Update Office titles  */ function update_office_titles() {     $  office_data = build_offices_array();     $  compare_ids = [];     foreach ($  office_data as $  office) {         $  compare_ids[] = [             'wp_office_id' => $  office['office_id']         ];     }     foreach (api_offices_raw() as $  api_office_id) {         $  compare_ids[] = [             'api_id' => $  api_office_id->id         ];     }      print_r($  compare_ids);      echo 'All of the office titles have been updated'; } 

Here, I’m grabbing all the office_id post_meta and getting all the post_meta values in the DB:

foreach ($  office_data as $  office) {     $  compare_ids[] = [         'wp_office_id' => $  office['office_id']     ]; } 

I get the following return:

[243] => Array     (         [wp_office_id] => 3     )  [244] => Array     (         [wp_office_id] => 4     ) 

Then I have this foreach that loops through an API with IDs:

foreach (api_offices_raw() as $  api_office_id) {     $  compare_ids[] = [         'api_id' => $  api_office_id->id     ]; } 

I get this output:

[246] => Array     (         [api_id] => 1     )  [247] => Array     (         [api_id] => 3     ) 

Here is what I was attempting to achieve:

Check api_id‘s and match them to the wp_office_id key values, if there are matching IDs, don’t do nothing, otherwise call a wp_update_post and set the status to pending on $ office['post_id'] on all IDs from wp_office_id that don’t match.

All help is appreciated!