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?

WBOY
Release: 2016-09-19 09:16:35
Original
1087 people have browsed it

For example, I have an array

<code>$arr = array();</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Thank you everyone

Reply content:

For example, I have an array

<code>$arr = array();</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Thank you everyone

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template