Wednesday, 17 August 2016

What does "->" do in PHP?




I am studying how to connect database while learning PHP. Just a quick question. Does anyone can tell me what does "->" sign do in PHP? I cannot understand the functionality of this sign so that I have no idea how to edit the code. Thank whoever answer this.


Answer



For real quick and dirty one-liner anonymous objects, just cast an associative array:




$obj = (object) array('foo' => 'bar', 'property' => 'value');


echo $obj->foo; // prints 'bar'
echo $obj->property; // prints 'value'

?>


... no need to create a new class or function to accomplish it.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...