PHP 8.4.0 RC4 available for testing

MongoDB\BSON\PackedArray::fromJSON

(mongodb >=1.20.0)

MongoDB\BSON\PackedArray::fromJSONConstruct a new BSON array instance from a JSON string

说明

final static public MongoDB\BSON\PackedArray::fromJSON(string $json): MongoDB\BSON\PackedArray

Converts an » extended JSON string to its BSON representation.

参数

json (string)

JSON value to be converted.

返回值

Returns a new MongoDB\BSON\PackedArray instance.

错误/异常

示例

示例 #1 MongoDB\BSON\PackedArray::fromJSON() example

<?php

$json
= '[ "foo", { "$numberInt" : "123" }, { "$numberLong" : "4294967295" }, { "$oid" : "56315a7c6118fd1b920270b1" } ]';
$packedArray = MongoDB\BSON\PackedArray::fromJSON($json);
var_dump($packedArray);

?>

以上示例会输出:

object(MongoDB\BSON\PackedArray)#1 (2) {
  ["data"]=>
  string(68) "MQAAAAIwAAQAAABmb28AEDEAewAAABIyAP////8AAAAABzMAVjFafGEY/RuSAnCxAA=="
  ["value"]=>
  array(4) {
    [0]=>
    string(3) "foo"
    [1]=>
    int(123)
    [2]=>
    int(4294967295)
    [3]=>
    object(MongoDB\BSON\ObjectId)#2 (1) {
      ["oid"]=>
      string(24) "56315a7c6118fd1b920270b1"
    }
  }
}

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top