How to create an array within an array?
P粉744831602
P粉744831602 2024-04-01 22:05:34
0
1
427

I have these two arrays. I want to create an array within an array like this. How can I do this. The code is posted below. This is the image I'm sending in fileToUpload. The array I have

Array
(
    [fileToUpload] => Array
        (
            [name] => KERINOX COFFEE.jpg
            [type] => image/jpeg
            [tmp_name] => /opt/lampp/temp/phpuk5Uyo
            [error] => 0
            [size] => 2440617
        )

)

The array I want

Array
(
    [fileToUpload] => Array
        (
            [name] => Array
                (
                    [0] => KERINOX COFFEE.jpg
                )

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

            [tmp_name] => Array
                (
                    [0] => /opt/lampp/temp/php0LlvE2
                )

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

            [size] => Array
                (
                    [0] => 2502103
                )

        )

)

P粉744831602
P粉744831602

reply all(1)
P粉211600174

You can simply use array_map to achieve this, wrapping each element into another array:

$data['fileToUpload'] = array_map(
  function($item) {
    return [$item];
  },
  $data['fileToUpload']
);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template