I am trying to check if two meta data has any common array values. Its returning an error

Notice: Array to string conversion in functions.php on line 1026 which is

$inbox = count(array_intersect($inmal, $newmails)) > 0 ? true : false;  

The full code is here:

$user = wp_get_current_user();
$newmails = get_user_meta( $user->ID, '_user_mailbox_new', true );
$newmails = isset( $newmails ) && is_array($newmails) ? $newmails : array();
$mails = get_user_meta( $user->ID, '_user_mailbox', true );
$inmal = isset($mails['inbox']) && is_array($mails['inbox']) ? $mails['inbox'] : array();
$svmal = isset($mails['saved']) && is_array($mails['saved']) ? $mails['saved'] : array();
$inbox = count(array_intersect($inmal, $newmails)) > 0 ? true : false;
$saved = count(array_intersect($svmal, $newmails)) > 0 ? true : false;  

I am getting the error for the last two lines. I am not getting why the error is there. Please help.

  • Are you sure that's the line 1026's code? Perhaps the problematic code is elsewhere.. because the code (in the question) seems working, though $mails should've been checked if it's an array, just like you did with the $newmails. – Sally CJ Sep 28 '18 at 10:59
  • 1
    @SallyCJ Sorry for the late reply mate. Yes, that was indeed line 1026. The problem was with the $mails['inbox'] array which I was assigning to $inmal. The $mails['inbox'] was a multidimensional array and $newmails was an indexed array, hence the problem. – Abhik Sep 30 '18 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.