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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:40:58+00:00 2026-05-23T16:40:58+00:00

I know CMap::mergeArray in Yii merges two array. But I have three array and

  • 0

I know CMap::mergeArray in Yii merges two array. But I have three array and I want to make them merge through CMap::mergeArray. So how to merge all the three array in Yii framework.

  • 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-23T16:40:59+00:00Added an answer on May 23, 2026 at 4:40 pm

    It depends on what you want. The key difference to note is that CMap will overwrite existing keys, which is different from the built in php functions:

    If each array has an element with the same string key value, the
    latter will overwrite the former (different from
    array_merge_recursive)

    If you do CMap::mergeWith as above, you’ll just be getting a new array consisting of the 3 arrays as subelements:

    For example, given the following structure:

    $foo = array (
        'a' => 1,
        'b' => 2,
        'c' => 3,
        'z' => 'does not exist in other arrays',
        );
    
    $bar = array (
        'a' => 'one',
        'b' => 'two', 
        'c' => 'three',
    );
    
    $arr = array (
        'a' => 'uno',
        'b' => 'dos',
        'c' => 'tres',
    );
    

    Using CMap::mergeWith as follows:

    $map = new CMap();
    $map->mergeWith (array($foo, $bar, $arr));
    print_r($map);
    

    Results in the following:

    CMap Object
    (
        [_d:CMap:private] => Array
            (
                [0] => Array
                    (
                        [a] => 1
                        [b] => 2
                        [c] => 3
                        [z] => does not exist in other arrays
                    )
    
                [1] => Array
                    (
                        [a] => one
                        [b] => two
                        [c] => three
                    )
    
                [2] => Array
                    (
                        [a] => uno
                        [b] => dos
                        [c] => tres
                    )
    
            )
    
        [_r:CMap:private] => 
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
    )
    

    If overwriting elements is the preferred behavior, then the following will work:

    $map = new CMap ($foo);
    $map->mergeWith ($bar);
    $map->mergeWith ($arr);
    print_r($map);
    

    Which results in:

    CMap Object
    (
        [_d:CMap:private] => Array
            (
                [a] => uno
                [b] => dos
                [c] => tres
                [z] => does not exist in other arrays
            )
    
        [_r:CMap:private] => 
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
    )
    

    If, however, you want the data appended, then:

    $map = new CMap (array_merge_recursive ($foo, $bar, $arr));
    print_r($map);
    

    Will get you there:

    CMap Object
    (
        [_d:CMap:private] => Array
            (
                [a] => Array
                    (
                        [0] => 1
                        [1] => one
                        [2] => uno
                    )
    
                [b] => Array
                    (
                        [0] => 2
                        [1] => two
                        [2] => dos
                    )
    
                [c] => Array
                    (
                        [0] => 3
                        [1] => three
                        [2] => tres
                    )
    
                [z] => does not exist in other arrays
            )
    
        [_r:CMap:private] => 
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know, I would have thought the answer was obviously no as well, but
I know there are similar questions already on SO but none of them seem
I know the input have the maxlength, but I would like to have minlength
I know we already have many posts about this topic, but I just cannot
I know I can do this by str.c_str() , but I do not want
know nothing about php, but I have this script that reads a folder and
I know I have done this before but I can't seem to remember where
I know that lot of questions about HTML sanitizers have appeared in SO, but
Know this might be rather basic, but I been trying to figure out how
I know this might be a no-brainer, but please read on. I also know

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.