Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:22:36+00:00 2026-06-12T15:22:36+00:00

I have the below piece of code which checks the given key exists in

  • 0

I have the below piece of code which checks the given key exists in the array. But when executing this code I get this error:

"Warning: array_key_exists() expects parameter 2 to be array, boolean given". I am new to PHP and no idea what causes this error.

Code

$structure = imap_fetchstructure($connection, $id, FT_UID);

if (array_key_exists('parts', $structure))
{

};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:22:37+00:00Added an answer on June 12, 2026 at 3:22 pm

    To protect against someone passing a boolean or null into the function, you can add a simple check to see if $structure is an array before using it:

        if (is_array($structure) && array_key_exists('parts', $structure))
        {
           //...magic stuff here 
        }
    

    The simple answer to ‘why’ your original code is broken is that imap_fetchstructure() isn’t finding the requested message and toand returning a false, null, or 0. The documentation http://php.net/manual/en/function.imap-fetchstructure.php doesn’t indicate what’s returned on failure, but it’s easy to guess. Most php functions that return objects but are unable to complete return a null or false on failure (when I say failure I don’t mean error or an exception, just couldn’t do or find whatever you asked of it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this below piece of code which makes me puzzling about internals of
I have a piece of matlab code below which reads data from a table.
I have a piece of code (below) that can get the text of an
I have a piece of ada code shown below which is a simple switch
I have this piece of code which i am using on another area of
I have this piece of code which works, however I would like to change
I have below piece code which runs on JDK5 private static ThreadLocal<String> messages =
I have a piece of code, copied below, with really similar structs in which
I have this piece of code which plays my mp3 files on my iphone
I have the below piece of code which Prefixs a string to the start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.