4

I searched all options for it, without success.

I have my Multidimensional Array like this:

Array 
(
[0] => Array
    (
        [0] => "Title1" 
        [1] => "Title2"
        [2] => "Title3"
    )
[1] => Array
    (
        [0] => "Title1"  
        [1] => "Title2"
    )
)
 Array #2

  Array
   (
[0] => Array
    (
        [0] => "Value1"  
        [1] => "Value2"
        [2] => "Value3"
    )
[1] => Array
    (
        [0] => "Value" 
        [1] => "Value2"
    )
)

And I would like to achive result like this:

New Array

Array
(
[0] => Array
    (
      [0] =>Array
          (
        [0] => "Title1"  
        [1] => "Title2"
        [2] => "Title3"
          )
          (
      [1] =>Array
          (
        [0] => "Title1"  
        [1] => "Title2"
          )
 )
 (

[1] => Array
    (
      [0] =>Array
          (
        [0] => "Value1"  
        [1] => "Value2"
        [2] => "Value3"
          )
          (
      [1] =>Array
          (
        [0] => "Value"  
        [1] => "Value2"
          )
    )
)

So I want to add 1 level of array, My thinking way is to loop through multidimensional array(2 loops) and by 3 loop add 2 next(on this example) array within. array_merge_recursive will not work. I tried to create proper loop, but without success. Is it possible??

3
  • 2
    I might be misreading, but do you just want to put both arrays into a single one? $newArray = [$array1, $array2]; ? Commented Jul 27, 2017 at 11:08
  • please show your code Commented Jul 27, 2017 at 11:08
  • 2
    $array = array( $array1, $array2 ); do you want? Commented Jul 27, 2017 at 11:08

3 Answers 3

2

You can do it like below (Assign both arrays to a new array):-

$arr3 = array($arr1,$arr2); // or [$arr1,$arr2];
print_r($arr3);

Output:-https://eval.in/838283

Sign up to request clarification or add additional context in comments.

2 Comments

Is it just so simple? :) I have something similar now, I will try to work with it in ajax. I think it will be accomplished with that. But the first of all, you tips are priceless. Thank you!
@Michał glad to help you :):)
1

Try like this-

$finalArray=[$arr1,$arr2]

Then you can add more array like

 $finalArray[] = $arr3;

Comments

0

Use array_merge() function

array_merge(array1,array2);

1 Comment

I don't think it will work.check with OP's array.Check here:- eval.in/838288

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.