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

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.…

Contents