PHP 5.2 array_push 插入空值

PHP 5.2 array_push inserts a null value

您好,我在迭代和推送数组中的值时遇到了一个奇怪的问题(为了更好地查看,我使用 json 数据)。下面是我在我的 foreach 中使用的数据,用于下面的数据。我实际上不知道问题是什么,但我正在使用 php 5.2

[
{
account_grp: "SOLD",
sold_to: "1000005071",
sold_to_name: "MARIA LUZ MANALILI",
ship_to: "1000005071",
ship_to_name: "MARIA LUZ MANALILI",
division: "20",
division_desc: "Pharma Sales",
salesman: "E000112086",
salesman_name: null,
doc_type: "DA",
posting_date: "20170707",
clearing: "2100030778",
doc_no: "1400009660",
assignment: "5110074314",
ref_no: "RC - RECLASS",
amt_w_vat: "6496.62",
vat: "779.5944",
amt_net_vat: "5717.0256",
cust_group2_desc: "MEAD JOHNSON",
cust_group_desc: "Reg Accnt-Non-Chain",
gl_account: "0000123001",
gl_account_desc: "TRADE RECEIVABLE",
check_date: null,
check_details: "RC - DAIF",
remarks: "RC - DAIF",
posting_key: "09",
line_item: "001",
fiscal_year: "2017",
tax_class: "1",
doc_no2: "1400009660"
},
{
account_grp: "SOLD",
sold_to: "1000004711",
sold_to_name: "PAZ PHARMACY",
ship_to: "1000004711",
ship_to_name: "PAZ PHARMACY",
division: "20",
division_desc: "Pharma Sales",
salesman: "E000071970",
salesman_name: "IGLORIA, JOAN DELICANO",
doc_type: "DA",
posting_date: "20170707",
clearing: "1700004713",
doc_no: "1400009658",
assignment: "5120008912",
ref_no: "RC - RECLASS",
amt_w_vat: "72783.62",
vat: "8734.0344",
amt_net_vat: "64049.5856",
cust_group2_desc: "INDEPENDENT",
cust_group_desc: "Reg Accnt-Non-Chain",
gl_account: "0000123001",
gl_account_desc: "TRADE RECEIVABLE",
check_date: null,
check_details: "RC - Tech Reason",
remarks: "RC - Tech Reason",
posting_key: "09",
line_item: "001",
fiscal_year: "2017",
tax_class: "1",
doc_no2: "1400009658"
},
{
account_grp: "SOLD",
sold_to: "1000003609",
sold_to_name: "DR. ANDEYLEF JOY S. CABUTIHAN",
ship_to: "2000003312",
ship_to_name: "DR. ANDELEYLEF JOY S. CABUTIHAN",
division: "20",
division_desc: "Pharma Sales",
salesman: "E000112086",
salesman_name: null,
doc_type: "DA",
posting_date: "20170714",
clearing: "2100031395",
doc_no: "1400009796",
assignment: "5110077391",
ref_no: "RC - RECLASS",
amt_w_vat: "11577.10",
vat: "1389.2520",
amt_net_vat: "10187.8480",
cust_group2_desc: "MEAD JOHNSON",
cust_group_desc: "Reg Accnt-Non-Chain",
gl_account: "0000123001",
gl_account_desc: "TRADE RECEIVABLE",
check_date: null,
check_details: "RC - DAIF",
remarks: "RC - DAIF",
posting_key: "09",
line_item: "001",
fiscal_year: "2017",
tax_class: "1",
doc_no2: "1400009796"
},
{
account_grp: "SOLD",
sold_to: "1000005447",
sold_to_name: null,
ship_to: "2000004135",
ship_to_name: null,
division: "20",
division_desc: "Pharma Sales",
salesman: "E000112086",
salesman_name: null,
doc_type: "DA",
posting_date: "20170720",
clearing: "2100031892",
doc_no: "1400010004",
assignment: "5130007369",
ref_no: "RC - RECLASS",
amt_w_vat: "11581.83",
vat: "1389.8196",
amt_net_vat: "10192.0104",
cust_group2_desc: "MEAD JOHNSON",
cust_group_desc: "Reg Accnt-Non-Chain",
gl_account: "0000123001",
gl_account_desc: "TRADE RECEIVABLE",
check_date: null,
check_details: "RC - DAIF",
remarks: "RC - DAIF",
posting_key: "09",
line_item: "001",
fiscal_year: "2017",
tax_class: "1",
doc_no2: "1400010004"
}
] 

这是我的代码

public function create($aData)
{

    $aValues = array();


    foreach ($aData as $key => $aReport) 
    {


        $sData = implode(',', $aReport);


        array_push($aValues, "(". $sData. ")");

    }
    echo json_encode($aValues);die();


}

当我回显 $aValues 时,这里是输出

[
null,
"(SOLD,1000004711,PAZ PHARMACY,1000004711,PAZ PHARMACY,20,Pharma Sales,E000071970,IGLORIA, JOAN DELICANO,DA,20170707,1700004713,1400009658,5120008912,RC - RECLASS,72783.62,8734.0344,64049.5856,INDEPENDENT,Reg Accnt-Non-Chain,0000123001,TRADE RECEIVABLE,,RC - Tech Reason,RC - Tech Reason,09,001,2017,1,1400009658)",
null,
null
]

它们显示为空,因为 json_encode 数据失败(格式不正确?)。确保您传递的数据格式正确,以便进行编码。

http://php.net/manual/en/function.json-encode.php