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

  • Home
  • SEARCH
  • 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 8471931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:55:49+00:00 2026-06-10T16:55:49+00:00

Basically I need to merge two arrays where the value 0 will take priority

  • 0

Basically I need to merge two arrays where the value 0 will take priority over 1.

I can’t find any native php function to do this, nor any function on google which surprised me (maybe i have been searching for the wrong things!), and I can’t think how to efficiently do it. Any suggestions?

For instance:

Array 1                   Array 2
  permission1 => 1            permission1 => 1
  permission2 => 1            permission2 => 1
  permission3 => 0            permission3 => 1
  permission4 => 0            permission4 => 1
                              permission5 => 1

The resulting array would be.

permission1 => 1
permission2 => 1
permission3 => 0
permission4 => 0
permission5 => 1

As you may have guessed this is for a permissions system. Nothing denotes no permission, 0 means never, and 1 means has permission. I thought the best solution might involve adding the two together and seeing if you get 1 or 2, but I can’t think how to implement this.

I hope this question is clear, just ask for clarification if not. Thanks in advance for suggestions.

  • 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-10T16:55:50+00:00Added an answer on June 10, 2026 at 4:55 pm
    foreach($array2 as $key => $val) {
       if (!isset($array1[$key])){
            $array1[$key] = $val;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically need to change the value that - admin_url() returns any idea?
I will be quick and simple on this. Basically I need to merge multiple
Basically I need to connect to the database without any existing databases. In SQL,
I an xsd file with multiple imports and includes. I need to basically merge
I need to merge two query results as in union, but I want to
I want to merge two Ruby modules without breaking the lookup chain. Basically I
Can anyone help with a SQL problem Im having whereby I need to merge
Basically need to generate custom(some different then yes no) messeges(alert) in JS , how
I basically need to get user input: gets.chomp(input?) And then to convert the given
I basically need a custom function to be used only when, for example, the

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.