在取消设置元素后重新排序数组键

时间:2014-08-09 09:26:12

标签: php arrays

我有一个类似

的数组
array (size=1)
  'images' => 
    array (size=3)
      0 => 
        array (size=4)
          'image_name' => string 'image name' (length=10)
          'image__seo_name' => string 'image-name' (length=10)
          'image_path' => string 'C:/wamp/www/folder/images/products/image.png' (length=45)
          'image_original_name' => string 'altinorfozotel7.png' (length=19)
      1 => 
        array (size=4)
          'image_name' => string 'image name 2' (length=12)
          'image_seo_name' => string 'image-name-2' (length=12)
          'image_path' => string 'C:/wamp/www/folder/images/products/image2.png' (length=46)
          'image_original_name' => string 'altinorfozotel3.png' (length=19)
      2 => 
        array (size=4)
          'image_name' => string 'image name 3' (length=12)
          'image_seo_name' => string 'image-name-3' (length=12)
          'image_path' => string 'C:/wamp/www/folder/images/products/image3.png' (length=46)
          'image_original_name' => string 'altinorfozotel4.png' (length=19)

我取消设置array['images'][0]键,需要重新排序array['images']数组中的数组键

我尝试使用array_values($array['images']),但'images'数组键已更改为0索引。

1 个答案:

答案 0 :(得分:1)

$array['images'] = array_values($array['images']);

应该有效