S
S
Sergey questions2018-06-24 23:04:43
PHP
Sergey questions, 2018-06-24 23:04:43

How to make the correct formation of a php array?

Hello. I form an array in PHP in this way:

<?php
  $massiv = array();
  
  foreach($deliveries as $delivery){
    $massiv[] = array(
      "type"=>"Feature", 
      "id" => $delivery->id,
      "geometry" => array(
        "type" => "Polygon",
        "coordinates" => $delivery->map
      )
    );
  };
  
  $result = array("type" => "FeatureCollection","features" => $massiv);
  echo json_encode( $result );
?>

But in the output, the id value and the coordinates value are enclosed in quotes. Those. instead of the right one: "id":12it turns out "id":"12"
Tell me how to exclude quotes from the id and coordinates values?
Currently outputting:
{"type":"FeatureCollection","features":[{"type":"Feature","id":"12","geometry":{"type":"Polygon","coordinates":"[]"}},{"type":"Feature","id":"13","geometry":{"type":"Polygon","coordinates":"[]"}}]}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-06-24
@smartycms

"id" => (int)($delivery->id),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question