以下是我想要输出的内容:
Array
(
[0] => Array
(
[restriction_type_code] => CALORICONTROL
[restriction_detail_code] => 3000CAL
)
[1] => Array
(
[restriction_type_code] => GLUTENFREE
[restriction_detail_code] => NR
)
)
我的实际代码如下:
foreach ($restriction as $value)
{
$itemSplit = explode("||", $value);
$itemSplit1 = explode("|", $itemSplit[0]);
$itemSplit2 = explode("|", $itemSplit[0]);
$arrOrderDiet['restriction_type_code'][] = $itemSplit1 //CALORICONTROL;
$arrOrderDiet['restriction_detail_code'][] = $itemSplit2//3000CAL;
}
我尝试了所有的可能性,但我认为我用完了解决方案。
答案 0 :(得分:2)
试试这个
foreach ($restriction as $value)
{
$itemSplit = explode("||", $value);
$itemSplit1 = explode("|", $itemSplit[0]);
$itemSplit2 = explode("|", $itemSplit[1]);
$arrOrderDiet[] = array('restriction_type_code' => $itemSplit1, 'restriction_detail_code' => $itemSplit2);
}
修改强>
foreach ($restriction as $value)
{
$itemSplit = explode("||", $value);
$itemSplit1 = explode("|", $itemSplit[0]);
$itemSplit2 = explode("|", $itemSplit[1]);
$arrOrderDiet[] = array('restriction_type_code' => $itemSplit1[0], 'restriction_detail_code' => $itemSplit2[2]);
}
答案 1 :(得分:0)
为什么两个指数在:
中相同$itemSplit1 = explode("|", $itemSplit[0]);
$itemSplit2 = explode("|", $itemSplit[0]);
不应该是这样的:
$itemSplit1 = explode("|", $itemSplit[0]);
$itemSplit2 = explode("|", $itemSplit[1]);
加:
$tmp['restriction_type_code'] = $itemSplit1[0];
$tmp['restriction_detail_code'] = $itemSplit2[0];
$arrOrderDiet[] = $tmp;