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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:25:23+00:00 2026-06-12T05:25:23+00:00

I am trying to set the values of an empty array with another array

  • 0

I am trying to set the values of an empty array with another array (based on rows returned from a database).

I have tried a few things like array_merge but I just end up adding to the first array.

Just curious if there is a way to do this or would I need to iterate thought each array and merge them?

The second array can have between 1 and 3 arrays in it, while the first (the “empty”) array has 3 elements always.

Empty array

(
    [0] => Array
        (
            [id] => 
            [quote_id] => 
            ...
        )

    [1] => Array
        (
            [id] => 
            [quote_id] => 
            ...
        )

    [2] => Array
        (
            [id] => 
            [quote_id] => 
            ...
        )

)

Array I want to copy data from

Array
(
    [0] => Array
        (
            [id] => 1
            [quote_id] => 1
            ...
        )

    [1] => Array
        (
            [id] => 2
            [quote_id] => 1
            ...
        )

) 

What I want to achieve

Array
(
    [0] => Array
        (
            [id] => 1
            [quote_id] => 1
            ...
        )

    [1] => Array
        (
            [id] => 2
            [quote_id] => 1
            ...
        )

      [2] => Array
        (
            [id] => 
            [quote_id] => 
            ...
        )

) 
  • 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-12T05:25:24+00:00Added an answer on June 12, 2026 at 5:25 am

    You can make use of the array union operatorDocs:

    $combined = $rows + $empty;
    

    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.

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

Sidebar

Related Questions

I am trying to get values from a data set. My function has to
I'm trying to set a value from the database into a Html component, the
here am trying to take the set of database values as comma separated and
I'm trying to fill out an array with values from checkboxes. It works just
I'm trying to get the collection prototype to have a set of default values
I am trying to set the values for the 2nd and 3rd corners on
I am trying to set the selected values for a MultiSelectList but the page
I am trying to store a set of values in delphi, but i want
I am trying to load/show completely different set of values in a combobox(this one
I am trying to find a way to set dict values encapsulated into a

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.