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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:18:19+00:00 2026-05-27T14:18:19+00:00

In PHP, ( given that $a , $b and $c are arrays ) is

  • 0

In PHP, (given that $a, $b and $c are arrays) is $a = array_replace($b, $c) always functionally identical to $a = $c + $b?

I can’t seem to find any edge cases that would indicate otherwise.

(just working with one dimension, this question isn’t concerned with recursion, ie: array_replace_recursive())


Edit: I found a note in a comment that suggests that the union operator will preserve references, but I haven’t noticed array_replace() failing to do that.

  • 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-05-27T14:18:20+00:00Added an answer on May 27, 2026 at 2:18 pm

    EDIT: Ah sorry, I didn’t notice the arguments were reversed. The answer is yes, then, because the resulting array always has the two arrays merged, but while + gives priority to values in the first array and array_replace to the second.

    The only actual difference would be in terms of performance, where + may be preferable because when it finds duplicates it doesn’t replace the value; it just moves on. Plus, it doesn’t entail a (relatively expensive) function call.


    No. array_replace replaces elements, while + considers the first value:

    <?php
    print_r(array_replace([0 => 1], [0 => 2]));
    print_r([0 => 1] + [0 => 2]);
    
    Array
    (
        [0] => 2
    )
    Array
    (
        [0] => 1
    )
    

    To cite the manual:

    The + operator returns the right-hand array appended to the left-hand array; for keys that exist in both arrays, the elements from the left-hand array will be used, and the matching elements from the right-hand array will be ignored.

    As for references, they are preserved in both cases.

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

Sidebar

Related Questions

I know that it's not possible to style any given PHP but I do
Is anyone aware of a script/class (preferably in PHP) that would parse a given
Given that I have a custom PHP error handler already, does it make sense
I'm trying to host a PHP web site that was given to me. I
For example, my goal is to test the code given here: PHP script that
I'm making a PHP image script that will create circles at a given radius.
I can't find any good documentation on the linkable behaviour for cakephp. I'm trying
What is the best way to take a given PHP object and serialize it
Given hello.php: <?php echo Hello; ?> rendering the page works fine and returns Hello
My clients home page is https://www.quakereadykit.com/store/home.php This was given to me by a previous

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.