PHP Interpolation Tutorial

hey guys what's going on it's clever techie and in this video we're going to cover PHP interpolation what is interpolation well it's a way to access arrays and methods and properties inside double quotes so I broken them down in four categories first is a preferred way then there's valid alternatives then there's the only way and finally there are all day invalid ways to access properties etc so let's go over the preferred method first so if you have an array with a single associated key and there's no spaces in that associated key you must enclose the whole thing and curly brackets now next at if you have just an America ray with a numeric e then you don't need any curly brackets for that and that's that only applies to single single dimensional arrays now this is a really cool one here if you have an object and you try to access a property name you don't need any curly brackets and this is the one that I've just found out about as i was making this video I thought that you had to close those in curly brackets before and as it turns out you don't have to so the system really clean way of accessing property names of your objects so next there's a valid alternatives ok so this one I also didn't know about so if you have a associative single dimensional array you try to access the associated key name you actually don't have to enclose it in the quotes in the single quotes in this case and PHP manual lid on it that's what they say you don't have to inclose that in in any quotes however it can get a little messy later on and if you try to print this out outside of double quotes it's not going to work also if you have a space in your associated key that's also not going to work out so i still prefer the preferred method of enclosing the associated key inside the curly brackets inside the double quotes when you have a single associated alrighty ok so if you have a numeric II can also close that in curly brackets but these are curly brackets are optional so I prefer this way here and also undervalued alternatives we have our property names you can also enclosed in curly brackets but they're also optional as I've just found out ok so the third is the only way you can access you can access the properties and in this case you are trying to access object method and you can access object method if you close it in curly brackets however that's not true for regular functions as you can see down here I've had concatenated the function with the dots with the concatenate operators so when it comes to object methods you can enclosed in curly brackets but when the one at when it comes to functions you must concatenated okay next up we gotta associated five single dimensional array with space which you must enclosed in curly brackets and for any multi-dimensional erase just remember that we have to enclose all multi-dimensional array keys in curly brackets whether they're a numeric or associative ok so function names you must concatenate and constant you also must concatenate constants you can just put them inside the double quotes with curly brackets or in any other way ok so invalid methods here you can see that I've printed the array with associated key outside the double quotes which is not going to work you're gonna get an error here up next is a constant enclosed in curly brackets which is not going to work as well next is a function named in closing curly brackets which is also not going to work as you can see the text highlighter is interpreted at the values as just strings next up we gotta object properties which are enclosed in single curly brackets that's invalid next we have a method call which is not in closing curly brackets that's not going to work as opposed to method properties next we got a multi-dimensional array which is not in closing curly brackets that's not going to work and cup next we gotta our array which is which gotta which is a multi-dimensional rate that has a string key followed by the numeric key which is enclosed in curly brackets now that is a tricky one because you can use a single dimensional array without enclosing the the key in single quotes but when it comes to multidimensional arrays you can't you absolutely must include i enclose the random key word here in the single or double quotes otherwise it's not gonna work ok next we got an associative array with a space in it that's not going to work so you must enclosed in curly brackets and next up we got a numeric multi-dimensional arrays which we also must in closing curly brackets and finally we got these two which are this is another way of accessing your keys outside of the array you can actually use curly brackets instead of square brackets but it's not going to work when it comes to enclosing when it comes to accessing them inside a double quotes so i definitely recommend using square brackets when accessing all array keys outside of double quotes so you guys can go ahead and download this sort of a cheat sheet to your computer and I hope is going to help you out if you like this video please go ahead and click like and i'll see you next time clever taking out