Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAshley Keeling
11,476 Pointswhy 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
2 Answers
Jovanny Elias
16,204 PointsHello, 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 StSomeWhere
19,870 PointsHi Ashley,
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?