0

I have an array called $result that I am trying to convert to JSON and the array looks like this

Array
(
    [0] => Array
        (
            [date] => 2014-07-10
            [amount_saved] => 700
        )

    [1] => Array
        (
            [date] => 2014-07-9
            [amount_saved] => 500
        )

    [2] => Array
        (
            [date] => 2014-07-8
            [amount_saved] => 900
        )

)

I need to convert it to make it look like the following JSON

[['2014-07-10', 700], ['2014-07-9', 500], ['2014-07-8', 900]];

If I do json_encode($result) I get the following output which is not what i need

[{"date":"2014-07-10","amount_saved":"700"},{"date":"2014-07-9","amount_saved":"500"},{"date":"2014-07-8","amount_saved":"900"}]

I will really appreciate if someone can help me in it

1 Answer 1

2

This will work.

$json = json_encode(array_map('array_values', $result));
Sign up to request clarification or add additional context in comments.

Comments

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.