Sometimes, we want to access an array/object with PHP.
In this article, we’ll look at how to access an array/object with PHP.
How to access an array/object with PHP?
To access an array entry with PHP, we can use square brackets.
And to access object properties, we use the ->
operator.
For instance, we write
echo $arr{0};
to print the first entry of the $arr
array.
To access object properties, we use the ->
operator.
For instance, we write
echo $foo->bar->property;
to print the value of the property
property in the bar
object that’s a property of the $foo
object.
Conclusion
To access an array entry with PHP, we can use square brackets.
And to access object properties, we use the ->
operator.