-4

Am trying to output an array from this JSON response

[
    [
        {
            "nombre": "TSU EN TICME",
            "nivel": 1,
            "numero": 4,
            "alias": "TICME",
            "inicio": "2016-09-02",
            "fin": "2019-09-26"
        },
        {
            "nombre": "TSU EN CONTADURIA",
            "nivel": 1,
            "numero": 6,
            "alias": "CONT",
            "inicio": "2016-09-03",
            "fin": "2019-09-27"
        }
    ]
]
4
  • That's a lot of downvotes for a brand new user. Maybe instead of simply downvoting, ya'll could provide some guidance that would actually be useful. ¯\_(ツ)_/¯ Commented Sep 26, 2019 at 19:50
  • 1
    Because it shows no research, this question was asked countless times Commented Sep 26, 2019 at 19:51
  • @CaddyDZ, I'm not saying the question doesn't merritt downvotes. I'm saying it's not particularly helpful for a brand new user to see a bunch of downvotes on their question without any explanation as to why. Commented Sep 26, 2019 at 19:53
  • Possible duplicate of how to convert json string to array in php? Commented Sep 26, 2019 at 19:55

1 Answer 1

2

You can use the json_decode (see docs) function to take the data you have and parse it into a php array.

$array = json_decode('[[{"nombre":"TSU EN TICME","nivel":1,"numero":4,"alias":"TICME","inicio":"2016-09-02","fin":"2019-09-26"},{"nombre":"TSU EN CONTADURIA","nivel":1,"numero":6,"alias":"CONT","inicio":"2016-09-03","fin":"2019-09-27"}]]');

Keep in mind, Laravel is not a programming language. It is a PHP framework. That's why you won't find this in the Laravel documentation. When you are looking for something like this, you should be searching the PHP documentation.

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

3 Comments

How can I reproduce it in a foreach or in a for?
@RaymundoAparicioOlarte, if this answer solved your problem, please upvote it, and mark it as "accepted" (checkmark), so that it can help other users in the future. Thanks!

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.