Monday 29 July 2019

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...