Can a single variable store both digits and characters in PHP?

Yes. If you put digits and characters together inside quotes, PHP stores them as a string. PHP is a loosely typed language, so you do not need to declare the type.

<?php
$variable = "Contact:24/7";

echo $variable . "<br>";
echo gettype($variable) . "<br>";

// The same variable can store another type later
$variable = 24;
echo gettype($variable);
?>

Output:

Tutorials Class - Output Window

Contact:24/7
string
integer

Remember that the value in quotes, like "24", is a string and not a number, even if it has only digits. Read PHP Data Types for more.


Learn more about the similar topics:
Tutorials
PHP Variables
PHP Data Types
PHP Constants
PHP isset() Function
PHP empty() Function
PHP is_null() Function
Exercises & Assignments
Write a program to print “Hello PHP” using variable
Write a program to print a string using echo+variable.
Write a program to print two variables in single echo
Interview Questions & Answers
How to check if a variable is empty in PHP?
Is PHP a case sensitive language?
What are the different data types in PHP?
How to define a Constant in PHP?
What is the difference between $var and $$var in PHP?
Which special characters are allowed in PHP variable names?
Can we print multiple variables in a single echo statement in PHP?