라이브러리

[PHP] MongoDBBSONDocument::fromPHP - PHP 데이터에서 새 문서 인스턴스 구성




MongoDBBSONDocument::fromPHP


`MongoDBBSONDocument::fromPHP`는 PHP에서 MongoDB의 BSON 문서를 생성하는 방법입니다. 이 메소드는 PHP의 배열 또는 객체를 MongoDB의 BSON 문서로 변환합니다.

# 사용법


`MongoDBBSONDocument::fromPHP` 메소드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

use MongoDBBSONDocument;



$document = Document::fromPHP([

    'name' => 'John Doe',

    'age' => 30,

    'address' => [

        'street' => '123 Main St',

        'city' => 'New York',

        'state' => 'NY',

        'zip' => '10001'

    ]

]);



print_r($document);



# 결과


#hostingforum.kr
php

MongoDBBSONDocument Object

(

    [_data:protected] => Array

        (

            [name] => John Doe

            [age] => 30

            [address] => Array

                (

                    [street] => 123 Main St

                    [city] => New York

                    [state] => NY

                    [zip] => 10001

                )



        )



)



# 객체를 사용한 예제


`MongoDBBSONDocument::fromPHP` 메소드는 객체를 사용하여도 가능합니다.

#hostingforum.kr
php

use MongoDBBSONDocument;



class User

{

    public $name;

    public $age;

    public $address;



    public function __construct($name, $age, $address)

    {

        $this->name = $name;

        $this->age = $age;

        $this->address = $address;

    }

}



$document = Document::fromPHP([

    'name' => 'John Doe',

    'age' => 30,

    'address' => new User('123 Main St', 'New York', 'NY', '10001')

]);



print_r($document);



# 결과


#hostingforum.kr
php

MongoDBBSONDocument Object

(

    [_data:protected] => Array

        (

            [name] => John Doe

            [age] => 30

            [address] => MongoDBBSONDocument Object

                (

                    [_data:protected] => Array

                        (

                            [street] => 123 Main St

                            [city] => New York

                            [state] => NY

                            [zip] => 10001

                        )



                )



        )



)



# 배열을 사용한 예제


`MongoDBBSONDocument::fromPHP` 메소드는 배열을 사용하여도 가능합니다.

#hostingforum.kr
php

use MongoDBBSONDocument;



$document = Document::fromPHP([

    'name' => 'John Doe',

    'age' => 30,

    'address' => [

        'street' => '123 Main St',

        'city' => 'New York',

        'state' => 'NY',

        'zip' => '10001'

    ]

]);



print_r($document);



# 결과


#hostingforum.kr
php

MongoDBBSONDocument Object

(

    [_data:protected] => Array

        (

            [name] => John Doe

            [age] => 30

            [address] => Array

                (

                    [street] => 123 Main St

                    [city] => New York

                    [state] => NY

                    [zip] => 10001

                )



        )



)



# 참고


* `MongoDBBSONDocument::fromPHP` 메소드는 PHP의 배열 또는 객체를 MongoDB의 BSON 문서로 변환합니다.
* 이 메소드는 MongoDB의 BSON 문서를 생성하는 데 사용할 수 있습니다.
* 이 메소드는 배열 또는 객체를 사용하여도 가능합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 408 페이지

검색

게시물 검색