Strings in PHP: Manipulation and Examples

Rumman Ansari   Software Engineer   2024-07-09 10:04:07   6024  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

PHP data types are used to hold different types of data or values. PHP supports the following data types:

  • String
  • Integer
  • Float
  • Boolean
  • Array
  • Object
  • NULL
  • Resource

PHP String

A string is a sequence of characters, like "Hello world!".

A string can be any text inside quotes. You can use single or double quotes:

Example code:


<?php

$x = "Hello world!";
$y = 'Hello world!';

echo $x;
echo "<br>";
echo $y;

?>


Output:

The above code will produce the following result-


Hello world!
Hello world!

PHP Resource

The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.

A common example of using the resource data type is a database call.

We will talk about the resource type in advanced topic.

MCQ Available

There are 14 MCQs available for this topic.

14 MCQTake Quiz


Stay Ahead of the Curve! Check out these trending topics and sharpen your skills.