Php JSON数组构造
我有一个JSON提要的一部分,我需要根据变量existance对其进行分段,但它是一个嵌套数组,我不太确定如何写下它 这是密码Php JSON数组构造,php,html,arrays,json,Php,Html,Arrays,Json,我有一个JSON提要的一部分,我需要根据变量existance对其进行分段,但它是一个嵌套数组,我不太确定如何写下它 这是密码 $postData += array( 'LineItems' => array( array( 'ItemName' => $_POST['milestone_1_detail'], 'Description' => 'Minimu
$postData += array(
'LineItems' => array(
array(
'ItemName' => $_POST['milestone_1_detail'],
'Description' => 'Minimum Guarantee - Installment 1',
'Quantity' => 1,
'Price' => $_POST['milestone_1_amount'],
'SellComm' => 0,
'BuyComm' => 0,
'Accept' => true
),
array(
'ItemName' => $_POST['milestone_2_detail'],
'Description' => 'Minimum Guarantee - Installment 2',
'Quantity' => 1,
'Price' => $_POST['milestone_2_amount'],
'SellComm' => 0,
'BuyComm' => 0,
'Accept' => true
),
array(
'ItemName' => $_POST['milestone_3_detail'],
'Description' => 'Minimum Guarantee - Installment 3',
'Quantity' => 1,
'Price' => $_POST['milestone_3_amount'],
'SellComm' => 0,
'BuyComm' => 0,
'Accept' => true
)
)
);
如您所见,它的三个(可能)项都列在父数组中
我需要做一个基本的测试
if ($_POST['milestone_1_amount']) { LineItem1 }
if ($_POST['milestone_2_amount']) { LineItem2 }
if ($_POST['milestone_3_amount']) { LineItem3 }
为所有三个项目键入条件,该条件仍会将这些子数组保留在父数组中,但仅显示设置了值的行项目,但不确定如何正确编写代码并保留数组格式
提前感谢您帮助我停止将头发撕下来我确实这样做了,但我不确定如何使子元素的数组结构保持完整我知道,但我也不确定如何使子元素的数组结构保持完整