本文介绍了在array_unique函数之后重新排列数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要PHP代码在调用array_unique函数后重新排列数组索引...

i used

array_unique($ a1)



i得到一个结果

数组([0] => [ 1] =>服装及配饰[130] =>婴儿及幼儿玩具[158] =>婴儿文具[162] =>沐浴及护肤[187] =>汽车座椅及配件[197] = >尿布[227] =>喂养[275] =>齿轮[296] =>礼品[319] =>健康和婴儿护理[328] =>托儿所[415] =>便盆训练[ 421] =>怀孕和孕妇[431] =>安全[445] =>鞋子[532] =>婴儿推车)



但我需要

数组([0] => [1] =>服装及配饰[2] =>婴儿及幼儿玩具[3] =>婴儿文具[4] =>沐浴&皮肤护理[5] =>汽车座椅及配件[6] =>尿布[7] =>喂养[8] =>齿轮[9] =>礼品[10] =>健康与婴儿护理[11] =>托儿所[12 ] =>便盆训练[13] =>怀孕与孕妇[14] =>安全[15] =>鞋子[16] =>婴儿推车)

Hi all,

I need PHP code to rearrange the array index after the array_unique function has been called...
i used
array_unique($a1)

i got a result as
Array ( [0] => [1] => Apparel & Accessories [130] => Baby & Toddler Toys [158] => Baby Stationery [162] => Bathing & Skin Care [187] => Car Seats & Accessories [197] => Diapering [227] => Feeding [275] => Gear [296] => Gifts [319] => Health & Baby Care [328] => Nursery [415] => Potty Training [421] => Pregnancy & Maternity [431] => Safety [445] => Shoes [532] => Strollers )

but i need
Array ( [0] => [1] => Apparel & Accessories [2] => Baby & Toddler Toys [3] => Baby Stationery [4] => Bathing & Skin Care [5] => Car Seats & Accessories [6] => Diapering [7] => Feeding [8] => Gear [9] => Gifts [10] => Health & Baby Care [11] => Nursery [12] => Potty Training [13] => Pregnancy & Maternity [14] => Safety [15] => Shoes [16] => Strollers )

推荐答案


a = array("one", "two", "two", "three")
a = array_unique(a);
/* will lead to:
a[0] = "one"
a[1] = "two"
a[3] = "three"
*/
a = array_values(a);
/* Now we've got:
a[0] = "one"
a[1] = "two"
a[2] = "three"
*/
?>





希望这会有所帮助..



Hope this helps..


这篇关于在array_unique函数之后重新排列数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 12:57