За последние 24 часа нас посетили 72740 программистов и 1650 роботов. Сейчас ищут 943 программиста ...

Подкажите решение по коду, как убрать индекс

Тема в разделе "PHP для новичков", создана пользователем marsik, 13 фев 2017.

  1. marsik

    marsik Активный пользователь

    С нами с:
    30 дек 2008
    Сообщения:
    246
    Симпатии:
    17
    Приветствую!

    Сам код:
    PHP:
    1. $json = array('type'=>'Feature','id'=>1,'geometry'=>array('type'=>'Point','coordinates'=>array(55.755814,37.617635 )),
    2. 'properties'=>array('balloonContent'=>'Russia','clusterCaption'=>'None','hintContent'=>'Russia'));
    3. $json[] = array('type'=>'Feature','id'=>2,'geometry'=>array('type'=>'Point','coordinates'=>array(55.755814,37.617635 )),
    4. 'properties'=>array('balloonContent'=>'Russia','clusterCaption'=>'None','hintContent'=>'Russia'));
    5.  
    6. exit(json_encode(array('type'=>'FeatureCollection','features'=>array($json))));
    Результат:
    HTML:
    1. {"type":"FeatureCollection","features":[{"type":"Feature","id":1,"geometry":{"type":"Point","coordinates":[55.755814,37.617635]},"properties":{"balloonContent":"Russia","clusterCaption":"None","hintContent":"Russia"},"0":{"type":"Feature","id":2,"geometry":{"type":"Point","coordinates":[55.755814,37.617635]},"properties":{"balloonContent":"Russia","clusterCaption":"None","hintContent":"Russia"}}}]}
    Надо результат как здесь:
    HTML:
    1. {
    2.     "type": "FeatureCollection",
    3.     "features": [
    4.         {"type": "Feature", "id": 0, "geometry": {"type": "Point", "coordinates": [55.831903, 37.411961]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}},
    5.         {"type": "Feature", "id": 1, "geometry": {"type": "Point", "coordinates": [55.763338, 37.565466]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}},
    6.         {"type": "Feature", "id": 2, "geometry": {"type": "Point", "coordinates": [55.763338, 37.565466]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}},
    7.         {"type": "Feature", "id": 3, "geometry": {"type": "Point", "coordinates": [55.744522, 37.616378]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}}
    8.     ]
    9. }
    Как убрать индекс (если я правильно его назвал) из моего кода? Заранее благодарю.
     
  2. alexblack

    alexblack Старожил

    С нами с:
    20 янв 2016
    Сообщения:
    640
    Симпатии:
    381
    Ну только если к первому $json добавить[]
    PHP:
    1. $json[]= array('type'=>'Feature','id'=>1,'geometry'=>
    2.                                             array('type'=>'Point','coordinates'=>array(55.755814,37.617635 )),
    3.                                          'properties'=>
    4.                                             array('balloonContent'=>'Russia','clusterCaption'=>'None','hintContent'=>'Russia'));
    5. $json[] = array('type'=>'Feature','id'=>2,'geometry'=>
    6.                                             array('type'=>'Point','coordinates'=>array(55.755814,37.617635 )),
    7.                                           'properties'=>
    8.                                             array('balloonContent'=>'Russia','clusterCaption'=>'None','hintContent'=>'Russia'));
    9. echo "<pre>";
    10. exit(json_encode(array('type'=>'FeatureCollection','features'=>array($json)),JSON_PRETTY_PRINT));
    Результат

    Код (Text):
    1. {
    2.     "type": "FeatureCollection",
    3.     "features": [
    4.         [
    5.             {
    6.                 "type": "Feature",
    7.                 "id": 1,
    8.                 "geometry": {
    9.                     "type": "Point",
    10.                     "coordinates": [
    11.                         55.755814,
    12.                         37.617635
    13.                     ]
    14.                 },
    15.                 "properties": {
    16.                     "balloonContent": "Russia",
    17.                     "clusterCaption": "None",
    18.                     "hintContent": "Russia"
    19.                 }
    20.             },
    21.             {
    22.                 "type": "Feature",
    23.                 "id": 2,
    24.                 "geometry": {
    25.                     "type": "Point",
    26.                     "coordinates": [
    27.                         55.755814,
    28.                         37.617635
    29.                     ]
    30.                 },
    31.                 "properties": {
    32.                     "balloonContent": "Russia",
    33.                     "clusterCaption": "None",
    34.                     "hintContent": "Russia"
    35.                 }
    36.             }
    37.         ]
    38.     ]
    39. }
     
    marsik нравится это.