PHP Tutorial 02 Learning about the Data types.

PHP Tutorial 02 : PHP Data type.

Php Tutorial 02 is discussing about variables and they can store using five difference data types such as,

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

Example for String,

<!DOCTYPE html>
<html>
<body>

<?php 
$x = "Tutorial 2";
$y = 'Tutorial 2';

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

</body>
</html>

Finally Integer.

In the PHP Tutorial 02 integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.

  • must have at least one digit
  • integer must not have a decimal point
  •  integer can contain positive or negative
  • Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation.
<?php
$y= 4567;
var_dump($y);
?>

PHP Tutorial 2 : Float.

Number with a decimal point or a number in exponential form.

<?php
$y = 78.345;
var_dump($y);
?>

PHP Boolean .

This is using for conditional testing.

$x = true;
$y = false;

PHP Array.

Store the multiple values in the single variables.

<?php
$color = array("Red","Blue","Black");
var_dump($color);
?>

PHP objects.

  • PHP latest version based on object-oriented programming.
  • Class is template for objects in the php langue.
  • Objects are instance of a class.
  • Each objects have different property values.
  • Class properties can inherit to the objects.
  • Constructor () function is automatically creating the object to the php code.
<?php
class Car {
  public $color;
  public $model;
  public function __construct($color, $model) {
    $this->color = $color;
    $this->model = $model;
  }
  public function message() {
    return "My car is a " . $this->color . " " . $this->model . "!";
  }
}

$myCar = new Car("black", "Volvo");
echo $myCar -> message();
echo "<br>";
$myCar = new Car("red", "Toyota");
echo $myCar -> message();
?>
PHP Tutorial 02

PHP null values.

  • This variable only can have value is “NULL”.
  • This variable does not have assign values.
  • When we are not assigning value to the variable it will automatically assigned to the NULL.
<?php
$x = "PHP Tutorial 02 ";
$x = null;
var_dump($x);
?>

PHP Resource.

  • This is not a variable type.
  • This is storing the resource external and reference to functional.

PHP String function.

There have several; strings functions.

Such as,

  • Strlen() – Returns the length of the srings.
  • str_word_count() – Return the number of words in the string.
  • Strrev() – Revers the string.
  • strpos() – search for text withining the string.
  • str_replace() – Replace the text withining the string.

This is using to manipulate the strings.

This PHP Tutorial 02 showing how to accept the three parameters, such as, number of characters, position of the string and string length.

Importance of the String function in the php.

  1. Counting Number of Words in String.
  2. Searching Text in String.
  3. Replacing Text in a String.
  4. Converting a Whole String into UPPERCASE and lowercase.
  5. Reversing a String.
  6. Comparing String.
  7. Finding Length of a String.
  8. Converting Lowercase into Title Case.
PHP Tutorial 02 Learning about the Data types

PHP Tutorial 01

3 thoughts on “PHP Tutorial 02 Learning about the Data types.”

Leave a Reply

Your email address will not be published. Required fields are marked *