[Solved] Convert PHP Associate Array [closed]


You can do this by encoding the array in JSON format.

Here’s the sample code for your better understanding:

<?php
$names = array(
        array(
            "foo"=> "bar",
        ),
        array(
            "foo"=> "bar",
        ),
        array(
            "foo"=> "bar",
        ),
    );
$namesJSON = json_encode($names);
echo "<pre>";
echo $namesJSON;
echo "</pre>"; 

?> 

This will output the JSON array which is required. Hope this answers your question. In order to generate the required JSON structure, you can read more about it on this JS Fiddle and this stack overflow question.

solved Convert PHP Associate Array [closed]