PHP的爆炸,while循环索引的数组应该开始的地方结束

你好,我在excel reader.php工作,我需要读取所有的产品id到一个数组。 在一个单元格中有很多产品id被“,”分开,所以我使用爆炸函数来获取它们。 那么这工作得很好,在第一个单元格,但然后我移动到其他,爆炸开始索引数组开始,所以id被添加到相同的variables。

例如

Cell 1 product id: 24,25,26 Cell 2 product id: 38,39,40 What i get with explode is $ids[0]=24 38 $ids[1]= 25 39 $ids[2]=26 40 Instead I want to get $ids[0]=24 $ids[1]=25 $ids[2]=26 ids[3]=38 ids[4]=39 

..等等

感谢您的build议!

使用array_merge连接数组:

 $ids = array(); while ($cell = <whatever you do to get a cell>) { $ids = array_merge($ids, explode(',', $cell)); } 
 $ids = array(); foreach (arrCell as $c) { $tmp = explode(',', $c); $ids = array_merge($ids, $tmp); }