Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Basic Math Operations | First Acquaintance
Introduction to PHP
course content

Зміст курсу

Introduction to PHP

Introduction to PHP

1. First Acquaintance
2. Variables and Data Types
3. Conditional Statements
4. Arrays
5. Loops

Basic Math Operations

Numbers


You already know how to use the echo function to output text. But what about numbers and mathematical calculations?

You can also use echo to display these. When you want to output the result of a mathematical expression, there's no need to use quotes (" " or ' '). Simply write the expression directly inside echo, and it will be evaluated and displayed on the screen.

php

main

If you print a number and a string to the console, they will look the same, which is something they have in common. However, there are things we can do with numbers that we can't do with strings, and vice versa. For instance, we can apply mathematical operations to numbers.

Math Operations


Almost no program can do without mathematical calculations, so PHP supports the following mathematical operations:

The code below performs basic arithmetic operations on different numbers and outputs the results to the screen.

Output the result of adding 5 and 3:

php

main

Output the result of subtracting 7 from 10:

php

main

Output the result of dividing 15 by 3:

php

main

Output the result of multiplying 4 by 6:

php

main

Output the remainder of dividing 17 by 5:

php

main

Завдання

Here's your assignment: compute the following and print the outcome: 1512 divided by 27.

Завдання

Here's your assignment: compute the following and print the outcome: 1512 divided by 27.

Все було зрозуміло?

Секція 1. Розділ 4
toggle bottom row

Basic Math Operations

Numbers


You already know how to use the echo function to output text. But what about numbers and mathematical calculations?

You can also use echo to display these. When you want to output the result of a mathematical expression, there's no need to use quotes (" " or ' '). Simply write the expression directly inside echo, and it will be evaluated and displayed on the screen.

php

main

If you print a number and a string to the console, they will look the same, which is something they have in common. However, there are things we can do with numbers that we can't do with strings, and vice versa. For instance, we can apply mathematical operations to numbers.

Math Operations


Almost no program can do without mathematical calculations, so PHP supports the following mathematical operations:

The code below performs basic arithmetic operations on different numbers and outputs the results to the screen.

Output the result of adding 5 and 3:

php

main

Output the result of subtracting 7 from 10:

php

main

Output the result of dividing 15 by 3:

php

main

Output the result of multiplying 4 by 6:

php

main

Output the remainder of dividing 17 by 5:

php

main

Завдання

Here's your assignment: compute the following and print the outcome: 1512 divided by 27.

Завдання

Here's your assignment: compute the following and print the outcome: 1512 divided by 27.

Все було зрозуміло?

Секція 1. Розділ 4
toggle bottom row

Basic Math Operations

Numbers


You already know how to use the echo function to output text. But what about numbers and mathematical calculations?

You can also use echo to display these. When you want to output the result of a mathematical expression, there's no need to use quotes (" " or ' '). Simply write the expression directly inside echo, and it will be evaluated and displayed on the screen.

php

main

If you print a number and a string to the console, they will look the same, which is something they have in common. However, there are things we can do with numbers that we can't do with strings, and vice versa. For instance, we can apply mathematical operations to numbers.

Math Operations


Almost no program can do without mathematical calculations, so PHP supports the following mathematical operations:

The code below performs basic arithmetic operations on different numbers and outputs the results to the screen.

Output the result of adding 5 and 3:

php

main

Output the result of subtracting 7 from 10:

php

main

Output the result of dividing 15 by 3:

php

main

Output the result of multiplying 4 by 6:

php

main

Output the remainder of dividing 17 by 5:

php

main

Завдання

Here's your assignment: compute the following and print the outcome: 1512 divided by 27.

Завдання

Here's your assignment: compute the following and print the outcome: 1512 divided by 27.

Все було зрозуміло?

Numbers


You already know how to use the echo function to output text. But what about numbers and mathematical calculations?

You can also use echo to display these. When you want to output the result of a mathematical expression, there's no need to use quotes (" " or ' '). Simply write the expression directly inside echo, and it will be evaluated and displayed on the screen.

php

main

If you print a number and a string to the console, they will look the same, which is something they have in common. However, there are things we can do with numbers that we can't do with strings, and vice versa. For instance, we can apply mathematical operations to numbers.

Math Operations


Almost no program can do without mathematical calculations, so PHP supports the following mathematical operations:

The code below performs basic arithmetic operations on different numbers and outputs the results to the screen.

Output the result of adding 5 and 3:

php

main

Output the result of subtracting 7 from 10:

php

main

Output the result of dividing 15 by 3:

php

main

Output the result of multiplying 4 by 6:

php

main

Output the remainder of dividing 17 by 5:

php

main

Завдання

Here's your assignment: compute the following and print the outcome: 1512 divided by 27.

Секція 1. Розділ 4
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt