Welcome to the Treehouse Community
Looking to learn something new?
Ashley Keeling11,476 Points
why would you need to know if two values are identical?
when would you use it in the real world? can you give an example please? thanks
Hello, first thing that comes to mind that we all use on a daily basis is to look something up on google or another search bar. All it does is it takes your value ex: "pizza" and compares this value to match with sites or articles you may be looking for. A google search is much more complicated than that but in its core that is all it is really doing.
You can also use it in games if player presses "A" you can add an action to the value "A" and if someone presses "B" those two values are not equal and thus the action of value "A" will be ignored.
In a math situation you can have even or odd situation where you want to see if the the input value is equal to odd or even so you would need to compare both and lets say if you want only an even number to be inputted and someone enters an odd number then then you may perhaps ask user to enter another number that is even. Your program would then compare all values entered until user finally enters an even value.
If it is still unclear let me know I can try to explain it differently.
Dave StSomeWhere19,822 Points
Great question and knowing the difference between identical and equals in php is a critical concept.
This explanation provides a pretty good walk through.
Two main real world issues jump out to me.
- Truthy checks for conditional expressions (like in the example link above).
- Data manipulation/validation/migration - for example we would want to treat an order number as a string, even through it contains only integer values. Also, ensuring a float or integer variable is of the correct type prior to doing any math.
Does that help?