0

I am getting the array from a api request for images which is the format as shown below. This array is very difficult to traverse and difficult for me to upload. I want a array in the single index which contains all the information of a single image. I have below given error:

Array
(
    [name] => Array
        (
            [0] => prog-programming_00267956.png
            [1] => programming-wallpaper_17695.jpg
        )

    [type] => Array
        (
            [0] => image/png
            [1] => image/jpeg
        )

    [tmp_name] => Array
        (
            [0] => /tmp/php0azGbU
            [1] => /tmp/phpyByFGB
        )

    [error] => Array
        (
            [0] => 0
            [1] => 0
        )

    [size] => Array
        (
            [0] => 587659
            [1] => 83817
        )

)

I have to convert it to:

    Array
    (
       [0] => Array
      (
        [name] => prog-programming_00267956.png
        [type] => image/png
        [tmp_name] => /tmp/phphSShmd
        [error] => 0
        [size] => 587659
      )
   [1] => Array
      (
        [name] => prog-programming_00267956.png
        [type] => image/png
        [tmp_name] => /tmp/phphSShmd
        [error] => 0
        [size] => 587659
      )
    )

So how to convert array into the above format.

0

1 Answer 1

7

Pretty smple.

$result = array();
foreach($array as $key1 => $value1) {
  foreach($value1 as $key2 => $value2) {
    $result[$key2][$key1] = $value2;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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.