Skip to content
Advertisement

How to add json with fixtures

On symfony I am trying to add some fixtures to the database some of which requires json format.

I tried :

$games->setMsrp(
                    {
                        'France': mt_rand(18, 80),
                    })

I tried different other variations but in vain

what is the correct way to do it?

Advertisement

Answer

You need to use the function json_encode to convert it into json.

$games->setMsrp(
    json_encode(
        [
            'France' => mt_rand(18, 80)
        ]
    )
);

Output: {"France":29}

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement