1$number = 11;
2// This
3echo strval($number);
4// Or This
5echo (String) $number;
6// Output
7// "11"
8// "11"
1$num = "3.14";
2$int = (int)$num;//string to int
3$float = (float)$num;//string to float
1$var = 5;
2
3// Inline variable parsing
4echo "I'd like {$var} waffles"; // = "I'd like 5 waffles
5
6// String concatenation
7echo "I'd like ".$var." waffles"; // I'd like 5 waffles
8
9// Explicit cast
10$items = (string)$var; // $items === "5";
11
12// Function call
13$items = strval($var); // $items === "5";
14
1phpCopy<?php
2$variable = 10;
3$string1 = strval($variable);
4echo "The variable is converted to a string and its value is $string1.";
5?>
6