Home >Backend Development >PHP Tutorial >c++ - How to pass objects to index array in PHP?

c++ - How to pass objects to index array in PHP?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-09-19 09:16:351101browse

For example, I have an array

<code>$arr = array();</code>

How to make a string correspond to an (object/object reference)

Similar to std::map

in C++

For example, if you want to implement code similar to the following, how should you do it in PHP?

<code>class Obj {
    int var;
}

Obj my_obj = new Obj();
std::string str = "str";

std::map<std::string,Obj> s_o;
s_0.emplace( {str,my_obj} );        </code>

Thank you everyone

Reply content:

For example, I have an array

<code>$arr = array();</code>

How to make a string correspond to an (object/object reference)

Similar to std::map

in C++

For example, if you want to implement code similar to the following, how should you do it in PHP?

<code>class Obj {
    int var;
}

Obj my_obj = new Obj();
std::string str = "str";

std::map<std::string,Obj> s_o;
s_0.emplace( {str,my_obj} );        </code>

Thank you everyone

array('str' => new Obj())

PHP is weakly typed, any data can be passed to an array

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn