0

I'm a beginner on php. This document is the result of a mongodb query.

Array ( [_id] => MongoId Object ( [$id] => 55e994585bab8c0a816e0693 ) [metadata] => Array ( [timestamp] => 1441371224596 ) [message] => Array ( [itsPduHeader] => Array ( [messageID] => 1 [protocolVersion] => 1 [stationId] => 33000 ) [denm] => Array ( [managementContainer] => Array ( [relevanceDistance] => 3 [referenceTime] => 363373455171 [stationType] => 15 [actionID] => Array ( [sequenceNumber] => 69 [orignatorStationID] => 33000 ) [detectionTime] => 363373438142 [eventPosition] => Array ( [altitude] => Array ( [altitudeValue] => 0 [altitudeConfidence] => 15 ) [posConfidenceEllipse] => Array ( [semiMajorOrientation] => 3601 [semiMinorConfidence] => 4095 [semiMajorConfidence] => 4095 ) [latitude] => 448848419 [longitude] => -5615145 ) ) [situationContainer] => Array ( [informationQuality] => 0 [eventType] => Array ( [subCauseCodeType] => 0 [causeCodeType] => 1 ) ) [locationContainer] => Array ( [traces] => Array ( [0] => Array ( [0] => Array ( [pathPosition] => Array ( [deltaAltitude] => 0 [deltaLongitude] => 0 [deltaLatitude] => 0 ) ) ) ) ) ) ) )

But I can't get the value of latitude and longitude. Can anybody help me?

Synchro
  • 35,538
  • 15
  • 81
  • 104
alex
  • 11
  • 2
  • 1
    possible duplicate of [How to read json properties using PHP](http://stackoverflow.com/questions/7279585/how-to-read-json-properties-using-php) – lukelazarovic Sep 07 '15 at 07:29
  • We need to decode the JSON value. check this URL [http://stackoverflow.com/questions/12429029/php-get-values-from-json-encode][1] – Prasanna Sep 07 '15 at 07:46
  • it's not all ready decoded? – alex Sep 07 '15 at 07:53
  • $doc = json_decode($doc, true); returns NULL – alex Sep 07 '15 at 07:59
  • http://php.net/manual/en/function.json-decode.php#refsect1-function.json-decode-returnvalues if in doubt check the doc – Sammaye Sep 07 '15 at 22:40
  • Looking at your question more you seem to actually be referencing "JSON" as the returned serialised object from the MongoDB query, which it is not. It is now a primitive object, a.k.a an array, as you're var_dump shows. Check this doc URL for array accession in PHP: http://php.net/manual/en/language.types.array.php – Sammaye Sep 07 '15 at 22:42
  • The problem is resolved i use: $doc["message"]["denm"]["managementContainer"]["eventPosition"]["latitude"] to get the value of latitude for exemple thank you all – alex Sep 08 '15 at 11:32

1 Answers1

0

Try:

$result = array();
echo $result['message']['denm']['managementContainer']['eventPosition']['latitude'];
echo $result['message']['denm']['managementContainer']['eventPosition']['longitude'];
Indrajeet Singh
  • 2,958
  • 25
  • 25