2

I am developing php API. I am creating emi_loan_date array from string. by doing this

"emi_date1" => explode(',', $row['emi_loan_date']),

which is look like this

"emi_date1": [
                "23-10-2019",
                "23-11-2019",
                "23-12-2019",
                "23-01-2020",
                "23-02-2020",
                "23-03-2020",
                "23-04-2020",
                "23-05-2020",
                "23-06-2020",
                "23-07-2020",
                "23-08-2020",
                "23-09-2020",
                "23-10-2020"
            ],


Now I want to pass other value named emi_amount in emi_date1. This would be look like this


"emi_date1": [
              {
               date: "23-10-2019",
               emi_amount: 2000
              },
              {
               date: "23-11-2019",
               emi_amount: 2000
              }
            ],



I am getting emi_amount in $row['emi_amount']

0

1 Answer 1

3

A simple foreach loop should do the trick (this does assume it's the same $row['emi_amount'] for all entries)...

$output = [];
foreach ( explode(',', $row['emi_loan_date']) as $date )    {
    $output[] = ['date' => $date, 'emi_amount' => $row['emi_amount']];
}
print_r($output);

One thing I would point out is that storing a comma separated list of items in a SQL column is generally a bad idea.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.