我有一个问题,我需要将explode(":",$productsOrdered)
转换为多级数组。将字符串分解为多级数组
我需要这样的:
$productsOrdered = "name:quantity:priceWithoutVat:vatAmount:priceWithVat:lineTotal:name:quantity:priceWithoutVat:vatAmount:priceWithVat:lineTotal:name:quantity:priceWithoutVat:vatAmount:priceWithVat:lineTotal:";
变成这样:
$productList = array(
array(name,quantity,priceWithoutVat,vatAmount,priceWithVat,lineTotal),
array(name,quantity,priceWithoutVat,vatAmount,priceWithVat,lineTotal),
array(name,quantity,priceWithoutVat,vatAmount,priceWithVat,lineTotal),
);
但我需要它的工作无论多少产品是如何在$productsOrdered
变量。 我用:
$product = explode(":",$product);
但我不知道如何将其转换成我需要的是一个多层次的数组。
不可能的。 explode()只能返回一个数组。如果你想要多维数组,你将不得不在循环中运行多个爆炸。 –
是已知的子数组中的项目数量? – EGN
如果这些只是相同的字符串,为什么不计算它们有多少,就像substr_count($ productsOrdered,'name:quantity:priceWithoutVat:vatAmount:priceWithVat:lineTotal'); 只需创建有序数组? –