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 8542065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:58:28+00:00 2026-06-11T11:58:28+00:00

Following up on this question and answer , I decided to accept boolean true

  • 0

Following up on this question and answer, I decided to accept boolean true and false only, and not even null from the input by other developer/ user.

$default = array(
    "category_id"   =>  null,
    "category"      =>  false,
    "randomise"     =>  false
);

$config = array(
    "category_id"   =>  17,
    "randomise"     =>  false, 
    "category"      =>  null
);

function process_array($default,$config)
{
    # Set empty arrays for error & items.
    $error = array();
    $items = array();

    # Loop the array.
    foreach($default as $key => $value)
    {
        if (is_bool($default[$key]) && isset($config[$key])) 
        {
            if ($config[$key] === null) $error[] = '"'. $key.'" cannot be null.';

            # Make sure that the value of the key is a boolean.
            if (!is_bool($config[$key])) 
            {
                $error[] = '"'. $key.'" can be boolean only.';
            }

        }

            if(isset($config[$key]) && !is_array($value))
            {
                $items[$key] = $config[$key];
            }
            elseif(isset($config[$key]) && is_array($value))
            {
                $items[$key] = array_merge($default[$key], $config[$key]);
            }
            else
            {
                $items[$key] = $value;
            }
        }

        # Give a key to the error array.
        $error = array("error" => $error);

        # Merge the processed array with error array.
        # Return the result.
        return array_merge($items,$error);
}

print_r(process_array($default,$config));

but result I get is,

Array
(
    [category_id] => 17
    [category] => 
    [randomise] => 
    [error] => Array
        (
        )

)

the result I am after,

Array
(
    [category_id] => 17
    [category] => 
    [randomise] => 
    [error] => Array
        (
         [0] => "category" cannot be null.
        )

)

So I thought this line below should work, but I don’t understand why it doesn’t. I tried to use is_null but still not working. Any idea what have I done wrong and how can I fix this?

if ($config[$key] === null) $error[] = '"'. $key.'" cannot be null.';
  • 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-11T11:58:29+00:00Added an answer on June 11, 2026 at 11:58 am

    isset($config[$key]) returns false if the value is null. use array_key_exists (http://php.net/manual/function.array-key-exists.php) instead.

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

Sidebar

Related Questions

I tried following the answer to this question , but could not get xsd.exe
Following this question and answer , I still have a bit trouble in the
In this answer to this question , Lachlan-Hunt writes the following: With HTML5, you
I have been following the answer of this question: How to update existing object
Following this question, it seems that it is possible to open a file from
Following on from this question , I am interested in finding out how you
following on from this question (Developing to an interface with TDD), I'm still having
Following on from this question...I'm trying to unit test the following scenario: I have
Following this question , I use this function to convert arrays to objects, function
Following up this question , I have a further problem - I have two

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.