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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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 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:
Using CMap::mergeWith as follows:
Results in the following:
If overwriting elements is the preferred behavior, then the following will work:
Which results in:
If, however, you want the data appended, then:
Will get you there: