What is type juggling? PHP changes the value to a specific data type based upon the context of how it is being used. Huh? For example, you are trying to compare a string number to a number. PHP converts the string to an integer for the comparison. It juggles the data type from string to integer.
It is important for you to know how type juggling works to ensure you get the results you require. It may not behave the way you think, which can lead to unexpected behavior in your code.
Watch the video(s) to learn more.
Show It in ActionBasic
To understand what type juggling is, you need to see it in action. In this video, you will learn about and see how type juggling:
- converts a string that starts with a number but has other characters after it
- converts a non-numeric string into an integer
- converts an integer into a floating point
Code. Eat. Code. Sleep. Dream about Code. Code.
Type juggling a string to array does not behave as you might expect. In this video, you will learn how and why.