I have this simple json object:
$colours = '{"num":20,"status":"ok","colour0":"red","colour1":"green","colour2":"blue"}';
How can I turn into this with PHP:
$colours = '[{"colour":"red"},{"colour":"green"},{"colour":"blue"}]';
Do I need to json_decode() it first ?
I tried this with no luck:
$jsonArr = json_decode($similarsites, true);
$c1 = parse_url($jsonArr['c1']);
$ii = 0;
$resulti = array('color' => array());
while (isset($jsonArr['c' . $ii])) {
$c = $jsonArr['c' . $ii];
$resulti['color'][$ii] = $c;
$ii++ ;
}
print json_encode($resulti['color']);
But this gives me the list of all colours not as key/value
{"red","green","blue"}