using -> in php
PHP =>
//The double arrow operator, =>
//Used as an access mechanism for arrays.
//The left side will have a corresponding value on the right side in array.
//This can be used to set values into a corresponding index of an array.
//The index can be a string or number.
$myArray = array(
0 => 'Red',
1 => 'Orange',
2 => 'Yellow',
3 => 'Green'
);
4
9
// Create a new instance of MyObject into $obj
$obj = new MyObject();
// Set a property in the $obj object called thisProperty
$obj->thisProperty = 'Fred';
// Call a method of the $obj object named getProperty
$obj->getProperty();
Thank you!
9
0
4
3
// Create a new instance of MyObject into $obj
$obj = new MyObject();
// Set a property in the $obj object called thisProperty
$obj->thisProperty = 'Fred';
// Call a method of the $obj object named getProperty
$obj->getProperty();
Thank you!
3
0
3.5
2
//The -> operator, also known as the object operator is used to access the properties and methods for a specific object.
// Besides, in simple words, the object operator -> is responsible for accessing an object method.
// for example: you a class 'Point' with a 'calculatePoint' method
$obj = new Point();
// setting a property of the Point class
$obj->x = 'value';
$obj->y = 'value';
// Calling a any method from our $obj
$obj->calculatePoint();
// Same implementation in Python
pyoObj = Point()
pyObj.x = 'value'
pyObj.y = 'value'
pyObj.calculatePoint()
// you should have something like that in most languages,
// I mean the '.propery()' instead of '->property()'
Thank you!
2
0
Are there any code examples left?
New code examples in category PHP