0
array (size=10)
  'image' => 
    array (size=3)
      0 => string 'BlackLingerie(42).jpg' (length=21)
      1 => string 'BlackLingerie(43).jpg' (length=21)
      2 => string 'BlackLingerie(44).jpg' (length=21)
  'text' => 
    array (size=3)
      0 => string '' (length=0)
      1 => string '' (length=0)
      2 => string '' (length=0)
  'author' => 
    array (size=3)
      0 => string '' (length=0)
      1 => string '' (length=0)
      2 => string '' (length=0)
  'date' => 
    array (size=3)
      0 => string '' (length=0)
      1 => string '' (length=0)
      2 => string '' (length=0)
  'verImage' => 
    array (size=3)
      0 => string 'upload' (length=6)
      1 => string 'upload' (length=6)
      2 => string 'upload' (length=6)
  'imagePicsPath' => 
    array (size=3)
      0 => string 'http://127.0.0.1/develop/mvc/public/images/pics/BlackLingerie(42).jpg'/' (length=77)
      1 => string 'http://127.0.0.1/develop/mvc/public/images/pics/BlackLingerie(43).jpg'/' (length=77)
      2 => string 'http://127.0.0.1/develop/mvc/public/images/pics/BlackLingerie(44).jpg'/' (length=77)
  'imageThumbPath' => 
    array (size=3)
      0 => string 'http://127.0.0.1/develop/mvc/public/images/thumbs/BlackLingerie(42).jpg'/' (length=79)
      1 => string 'http://127.0.0.1/develop/mvc/public/images/thumbs/BlackLingerie(43).jpg'/' (length=79)
      2 => string 'http://127.0.0.1/develop/mvc/public/images/thumbs/BlackLingerie(44).jpg'/' (length=79)
  'imagePath' => 
    array (size=3)
      0 => string 'http://127.0.0.1/develop/mvc/public/images/pics/BlackLingerie(42).jpg'/' (length=77)
      1 => string 'http://127.0.0.1/develop/mvc/public/images/pics/BlackLingerie(43).jpg'/' (length=77)
      2 => string 'http://127.0.0.1/develop/mvc/public/images/pics/BlackLingerie(44).jpg'/' (length=77)
  'imageID' => 
    array (size=3)
      0 => string '0' (length=1)
      1 => string '1' (length=1)
      2 => string '2' (length=1)
  'submitUploadImages' => string 'Ladda upp bilder till databas' (length=29)

想将此数组重建为更有用的数组。像这样

array
   ( [image0] (
       'name' => 
       'text' => 
       'author' => 
       'date' => 
       'verImage' => 
       'imagePicsPath' => 
       'imageThumbPath' => 
       'imagePath' => 
       'imageID' => 
      )
      [image1] (
       'name' => 
       'text' => 
       'author' => 
       'date' => 
       'verImage' => 
       'imagePicsPath' => 
       'imageThumbPath' => 
       'imagePath' => 
       'imageID' => 
      )

依此类推,取决于有多少张图片,图像数组中的键保存每个图像的值。比如名字,路径等等。传入的数组是一个 $_POST ,它包含多个表单输入数据。需要一些帮助来破解这个家伙。需要遍历 $_POST 数组,获取内容并转换为新数组?

在使用数据库做我的事情之前,我想要唯一的图像数组来保存图像信息 =)

4

3 回答 3

2

尝试

foreach( $array as $1st_level_key => $1st_level_value ) {
    foreach ( $1st_level_value as $2nd_level_key => $2nd_level_value ) {
        $new_array['image'.$2nd_level_key][$1st_level_key] = $2nd_level_value;
    }
}
于 2013-04-19T18:37:23.027 回答
2

我没有对此进行测试,但它应该可以工作:

$incomingArray = $_POST['array'];
$sortedArray = array();

for($i = 0; $i < count($incomingArray); $i++){
    foreach($incomingArray as $key => $value){
        $sortedArray["image".$i][$key] = $value[i];
    }
}

这样做意味着您不必$sortedArray["image".$i]['NAME'] = $incomingArray['NAME'][$i]为每个图像值(名称、测试、作者等)编写。

于 2013-04-19T18:33:41.973 回答
0

简短的回答是的,差不多是这样的:

for($i = 0; $i < count($YourArray); $i++)
{
    $NewArray["image".$i]["name"] = $YourArray["name"][$i];
    ...
}
于 2013-04-19T18:29:58.660 回答