Json-array von Objekten in php

dies ist die, dass meine json-code erzeugt

{
"aaa":1,
"b":2,
"c":3,
"d":4,
"e":5,
"fff":{"a":11111,"b":222222,"c":33333,"d":444454,"e":55555555}
}

- und dies ist der code

<?php
$c = array('a' => 11111, 'b' => 222222, 'c' => 33333, 'd' => 444454, 'e' => 55555555 );
$arr = array('aaa' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 , 'fff'=>$c);
echo json_encode($arr);
?>

aber ich möchte ein paar Gebäude wie dieses

{
"aaa":1,
"b":2,
"c":3,
"d":4,
"e":5,
"fff":{"a":11111,"b":222222,"c":33333,"d":444454,"e":55555555},
"last":[
      {
        "id": 8817,
        "loc": "NEW YORK CITY"
      },
      {
        "id": 2873,
        "loc": "UNITED STATES"
      },
      {
        "id": 1501,
        "loc": "NEW YORK STATE"
      }
    ]
}

Ich bin neu in json und php und ich brauche diese so schnell, ich habe keine Zeit zum Lesen über dieses json-Struktur... Also bitte, wenn jemand weiß, wie das hinzufügen dieses Letzte element bitte geben Sie einige php-code.

Dank,

  • wo werden die Daten von last
  • Uhm... fügen Sie einfach ein "last" array zu Ihrer $arr?
InformationsquelleAutor Lukap | 2011-11-08
Schreibe einen Kommentar