Json type array with php how?

Hi everyone…

just need little help if I’m give such string


how to outputingg json type array as u can see below…any shed some light are appreciate…


thanks in advanced


$string = '1447615481,0,0||1052646429,0,0';

$a = new stdClass;
$b = new stdClass;

list($a->coor, $a->x, $a->y, $b->coor, $b->x, $b->y) = sscanf($string, '%d,%d,%d||%d,%d,%d');

echo json_encode(array($a, $b));

This should give you the desired result

$coordinates = '1447615481,0,0||1052646429,0,0';
$coordinates = explode('||', $coordinates);
$output = array();

foreach ($coordinates as $coordinate) {
    $temp = explode(',', $coordinate);
    array_push($output, array('coor' => $temp[0], 'x' => $temp[1], 'y' => $temp[2]));

echo json_encode($output);

NOTE: The json_encode and json_decode functions only work on PHP 5.2 and higher, if your server doesn’t support this you will need to get the JSON PHP library which can be found at http://www.json.org


it do the tricks now…million thanks to AnthonySterling and SgtLegend for the concern…tq again…