Strings in PHP are sequences of characters enclosed in single quotes (' ') or double quotes (" ").
<?php
$name = "Samir";
$greeting = 'Hello World';
echo $name;
echo $greeting;
?>
<?php
$str = "Hello";
echo strlen($str); // Length of string
echo strrev($str); // Reverse string
echo strtoupper($str); // Convert to uppercase
echo strtolower($str); // Convert to lowercase
echo str_replace("Hello", "Hi", $str); // String replace
?>
<?php
$first = "Hello";
$second = "PHP";
echo $first . " " . $second; // Using dot operator
?>
👉 Explanation:
.) is used to join strings.strlen(), strrev(), strtoupper(), etc.Numbers in PHP can be integers or floating-point values. PHP automatically detects the number type.
<?php
$x = 10; // Integer
$y = 20.5; // Float
echo $x;
echo $y;
?>
<?php
$a = 10;
$b = 3;
echo $a + $b; // Addition
echo $a - $b; // Subtraction
echo $a * $b; // Multiplication
echo $a / $b; // Division
echo $a % $b; // Modulus
?>
<?php
$num1 = 100;
$num2 = 20.55;
var_dump(is_int($num1)); // Check integer
var_dump(is_float($num2)); // Check float
var_dump(is_numeric("50")); // True: numeric string
?>
👉 Explanation:
is_int(), is_float(), and is_numeric() help check number types.