![]() ![]() Otherwise (private or protected) you need a method or reflection, which you can use to get the value of the property. You can only access properties with public visibility from outside of the class. And especially this one if you have numbers at the start of the property name. echo $objectA->objectB->property Īlso you have to be careful if you have a property name which is invalid! So to see all problems, which you can face with an invalid property name see this question/answer. If you have an object in another object you just have to use multiple -> to get to your object property. To access an object property you have to use ->. To access an array element in a sub array you just have to use multiple. If you have multiple arrays in each other you simply have a multidimensional array. So just be aware of what expression you use as key and how it gets interpreted by PHP: echo $array //The key is an integer It accesses the 0's elementĮcho $array //The key is a string It accesses the 0's elementĮcho $array //The key is a string It accesses the element with the key 'string'Įcho $array //The key is a constant and it gets replaced with the corresponding valueĮcho $array //The key is also a constant and not a stringĮcho $array //The key is a variable and it gets replaced with the value which is in '$anyVariable'Įcho $array //The key will be the return value of the function ![]() On older PHP versions, an alternative syntax using which then evaluates to the key you want to access: $array To access array elements you have to use. ![]() To access an array or object you how to use two different operators. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |