From the course: PHP for WordPress (2020)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Arithmetic operators and math in PHP - PHP Tutorial
From the course: PHP for WordPress (2020)
Arithmetic operators and math in PHP
- [Instructor] Performing mathematical operations is another important aspect of PHP in general. In WordPress specifically, you're likely incrementing or decrementing to traverse through an array. But due to WordPress' vast scope, you can do just about anything, from iterate through blog posts to create complex e-commerce calculations. To start there are five arithmetic operators you can perform. Addition with the plus sign. Subtraction with the minus sign or the dash. Multiplication with an asterisk. Division with a forward slash. Or you can get the remainder with the percent sign. You can perform these operations in variable assignments or directly output them using echo. In both of these cases, the output is two. PHP is smart enough to recognize when we're using literal numbers and not strings. So it will evaluate the variable or the literal operation before outputting it to the screen. Here are some more examples.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What is PHP?2m 1s
-
(Locked)
Printing information3m 15s
-
(Locked)
What are variables?6m
-
(Locked)
Strings in PHP5m 57s
-
(Locked)
Using arrays7m 59s
-
(Locked)
Arithmetic operators and math in PHP4m 38s
-
(Locked)
Challenge: Perform a mathematic operation and store it1m 14s
-
(Locked)
Solution: Perform a mathematic operation and store it3m 33s
-
-
-
-
-