Join Kevin Skoglund for an in-depth discussion in this video Add additional units, part of Easy PHP Projects: Measurement Conversion.
- In the previous movie, we learned…to convert feet into meters.…Now we're ready to apply the same concept…to converting other units of length into meters.…Here's a chart of the conversion values…that we'll be using.…If you decided to use different conversion units than I did,…you'll need to look up the value to use…for converting your units into meters.…Now that we have the chart,…let's add the corresponding conversion formulas…to our PHP code.…We're going to be working inside…our convert_to_meters function.…Now, let's say we wanted to add support for inches.…
We could put another if statement here.…If from unit…equals inches,…and then have a block of code there.…We could even then make this an elseif, if we wanted.…But I think that instead of having a lot…of if-else's strung together, a better way to do this…is to use PHP's switch statement.…This is what switch statements are really good for.…So based on the value of $from_unit,…we're going to execute a bit of code.…And for each one of those, we need…to say what the case is:…
Along the way, series designer Kevin Skoglund introduces coding strategies, refactoring techniques, and useful skills including dynamically generating form select-option values and formatting decimal numbers and scientific notation.
- Converting length and area measurements
- Using functions to avoid repetition
- Refactoring to produce simpler code
- Converting volume and mass
- Generating form select-option values dynamically
- Formatting scientific notation
- Converting speed and temperature
Skill Level Beginner
PHP: Accessing Databases with PDO and MySQLiwith David Powers3h 47m Intermediate
1. Length and Distance
3. Volume and Capacity
4. Mass and Weight
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.