🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to define PHP variable type conversion operators?

In this blog, I am going to explain Variable Type & Type Conversion in PHP.
variable type depends on the value of currently holds means when you declare a variable in PHP, You do not declare its type.

$value = “This is Variable”; // assign string
echo $value;

you can change variable’s type by assigning a new value of different type.

$val = 44; // integer string
echo $val;

Automatic type conversion-

A variable type can depend upon the text in which it is used. Some functions and operators can be expect the value of a particular type convert automatically that type of its value.

$val = array('first', 'second', 'third');
echo "This is Automatic type conversion " . $val[0] . ' example <br>';
echo "This is Automatic type conversion " . $val[1] . ' example<br>';
echo "This is Automatic type conversion " . $val[2] . ' example<br>';
// $var is set as an integer = 25
$var = "10" + 15;
// $var is set as a float = 25.0
echo $var;
$var = "10" + 15.0;
// $var is set as a string = "15 Steps"
echo $var;
$var = 15 . " Steps";
echo $var;

Output-

settype() – Change Variable’s Data Type-

The function settype($value, “Type”) can clearly set the type of variable to type where the type’s value may be array, string, boolean integer, object, null. then uses of settype($value “Type”).

<?php
$var = 2.23;
echo $var; // Displays "2.23"
echo gettype($var);
echo '<br>';
//prints double
settype( $var, "string" );
echo $var; // Displays "2.23"
echo gettype($var);
echo '<br>';
//prints string
settype( $var, "integer" );
echo $var; // Displays "2"
echo gettype($var);
echo '<br>';
//prints integer
settype( $var, "float" );
echo $var; // Displays "2"
echo gettype($var);
//prints double
settype( $var, "boolean" );
echo $var; // Displays "1"
echo gettype($var);
echo '<br>';
//prints boolean
settype( $var, "null" );
echo $var; // Displays nothing
echo gettype($var);
//prints NULL
?>

Output

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.