Jump to content

[SOLVED] Split multidimensional array to two seperate arrays ?


ttmt

Recommended Posts

Hi all

 

I have a multidimensional array (one array that contains 2 other arrays).

 

Array
(
  [0] => Array
      (
          [0] => 26
          [1] => 27
          [2] => 28
      )

  [1] => Array
      (
          [0] => .jpg
          [1] => .jpg
          [2] => .jpg
      )

)

 

I want to split this array into two seperate arrays like so

 

Array
(
  [0] => 29
  [1] => 30
  [2] => 31
)

Array
(
  [0] => .jpg
  [1] => .jpg
  [2] => .jpg
)

 

I tried this - $photo_id_ext_arr is the multidiemsional array

 

for($i=0;$i<=count($photo_id_ext_arr);$i++){
		array_push($photo_id, $photo_id_ext_arr);
		array_push($ext, $photo_id_ext_arr);
}
print_r($photo_id);
print_r($ext);

 

but it produces 3 of everything - I can see why it's doing it but I can't see how to produce 1 of each.

 

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => 24
                    [1] => 25
                )

            [1] => Array
                (
                    [0] => .jpg
                    [1] => .jpg
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [0] => 24
                    [1] => 25
                )

            [1] => Array
                (
                    [0] => .jpg
                    [1] => .jpg
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [0] => 24
                    [1] => 25
                )

            [1] => Array
                (
                    [0] => .jpg
                    [1] => .jpg
                )

        )

)
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => 24
                    [1] => 25
                )

            [1] => Array
                (
                    [0] => .jpg
                    [1] => .jpg
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [0] => 24
                    [1] => 25
                )

            [1] => Array
                (
                    [0] => .jpg
                    [1] => .jpg
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [0] => 24
                    [1] => 25
                )

            [1] => Array
                (
                    [0] => .jpg
                    [1] => .jpg
                )

        )

)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.