I want to separate this array into multiple arrays depending on how many files there is.
Array
(
[files] => Array
(
[name] => Array
(
[0] => pic1.png
[1] => pic2.png
)
[type] => Array
(
[0] => image/png
[1] => image/png
)
[tmp_name] => Array
(
[0] => C:\Windows\Temp\php893F.tmp
[1] => C:\Windows\Temp\php895F.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
)
[size] => Array
(
[0] => 777180
[1] => 734111
)
)
)
I want it to look like this:
Array
(
[files] => Array
(
[0] => array
(
[name] => pic1.png
[type] => image/png
[tmp_name] => C:\Windows\Temp\php893F.tmp
[error] => 0
[size] => 777180
)
[1] => array
(
[name] => 开发者_JAVA技巧pic2.png
[type] => image/png
[tmp_name] => C:\Windows\Temp\php895F.tmp
[error] => 0
[size] => 734111
)
)
)
If your actual input array has the same structure and keys like that you provided in your question, then this piece of code should work:
$separated = array();
foreach ($array['files'] as $property => $values)
{
foreach ($values as $key => $value)
{
$separated[$key][$property] = $value;
}
}
精彩评论