我有一個數組是這樣的:如何在兩個數組分割字符串在Php
$array='{b_price,9500,b_discount,10,mainPrice,95000,total,95000,title,obj1},{b_price,1500,b_discount,15,mainPrice,15000,total,22500,title,obj2}'
我想先拆分兩個數組是這樣的:
$array[0]={b_price,9500,b_discount,10,mainPrice,95000,total,95000,title,obj1}
而且
$array[1]={b_price,1500,b_discount,15,mainPrice,15000,total,22500,title,obj2}
我用此代碼更改每個陣列
foreach ($b as $k => $m) {
if ($k % 2 == 0) {
$even[]= $m;
}
else {
$odd[] = $m;
}
}
$ff=array_combine($even,$odd);
我想這樣
Array(Array[0] => ([b_price] => 9500 [b_discount] => 10 [mainPrice] => 95000 [total] => 95000 [title] =>obj1)
Array[1] => ([b_price] => 1500 [b_discount] => 15 [mainPrice] => 15000 [total] => 22500 [title] => obj2))
首先添加{B_PRICE之前,然後用爆炸它,因爲分隔符 –
它不是一個數組,基本上它是一個字符串,$陣列='{B_PRICE,9500,b_discount,10,mainPrice,95000 ,總數,95000,title,obj1},{b_price,1500,b_discount,15,mainPrice,15000,total,22500,title,obj2}' –
我用這段代碼展開了第一個數組$ b1 = explode(「{」,$數組); – Saeidhp