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
                )

        )

)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.