Type Casting to Integers in PHP
Let's say, for example, we have a string with digits:
php<?php
$test = '1';
var_dump($test);
?>
Let's convert it to an integer. For
this, we will use the special command int,
like this:
php<?php
$test = (int) '1';
var_dump($test); // will output 1 - a number
?>
You can use the type casting command directly in the function call:
php<?php
var_dump((int) '1');
?>
You can convert the value of a variable:
php<?php
$test = '1';
var_dump((int) $test);
?>
Задание 1
Convert the following string to a number:
php<?php
$test = '12345';
?>