1

Hi I'm encountering a weird problem iterating and pushing a value in an array(for better viewing i use json data). Below is the data i'm using in my foreach for the data below. I actually don't know what the problem is but i'm using 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"
}
] 

here's my code

public function create($aData)
{

    $aValues = array();


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


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


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

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


}

and when i echo the $aValues here's the output

[
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
]

1 Answer 1

1

They are displaying null because json_encode is failing on the data (not properly formatted?). Make sure you are passing in properly formatted data to be encoded.

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

Sign up to request clarification or add additional context in comments.

4 Comments

hi actually i use json data for better viewing but the data format is in Array
json_encode doesn't like it, post your actual php array and maybe someone can pinpoint an issue.
Hi btw your right i tried var_dump and the value is not null anymore , i'll check further why the data is failing Thank you very much
use echo '<pre>'; var_export( $var ); if you want the php output formatted the best way. I prefer var_export as it outputs valid "Stuff" in php format. Essentally you could copy the output of an array from var_export right into php code. The <pre> tag preserves whitespace, no need to close it for testing purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.