Scalar data types in php

In php four data types

  1. Boolean
  2. Integer
  3. Float
  4. String
Boolean data type in php

This data type can represent either true or false . In PHP value is 1 and value of false doesn’t any value.
is_bool : Using this function , we can check input variable is boolean or not.
(bool) var  OR  (boolean) var     using this function , we  convert variable into boolean variable.

Integer data type in php

This data type can store numeric value
is_int  OR  is_integer    it is used to  cheak input variable is integer or not .
(int)var ))OR  (integer) var  OR intval(var)    Using this function , we convert variable into integer variable.

Float data type in photo

this  data type  can store decimal values .

is_float ()  this function cheacks input variuable  is float or not.
(float)var   Converts a variable into floating point number.

String data type in php

It is a collection of character.
In PHP , we can declar string in  three ways.

  1.    By using single quotations
  2.    By using double quotations
  3.    By using heredoc syntax

NOTE  Variable in double quotations returns value of variables.

Heredoc   PHP suports heredoc  syntax to avoid the conflicts what we getting with single and double quotations.


Compound data types

  • Array :- Array is a collection of heterogenous elements .
  • Object :- Object is an instance of class.

Special Data type
Resource :-  This data type can refer external resoures like database connections , file pointers  etc.
Null data types :- In PHP , null is not  a value . we can consisder a varible as null variable based on three conditions.

  •  if variable is not set with any value.
  • if variable is set with null .
  • if variable’s value is unset.

is_null()  Using this function , we can check input variable is null or not .

String functions in PHP 
  1. Strlen()  to get length of string.

Note :- Ord() used for getting ASCII value

  1. strtoupper() ;-  Converts all character of a string into uppercase .
  2. strto lower() : Converts characters of a string into lower case .
  3. ucfirst(): Converts first characters of string into upper case .
  4. ucwords(): Converts first character of all words into upper case .
  5. nl2br() :  to break new lines of string.
  6. Str_word_count() :  To get total number of words of a string .
    1. We can pass node value, if node value is 0. It returns total no of words.
    2. If node value is 1, It returns each word as array elements has a numeric key 0,1,2. Etc.
    3. If node value is 2, It returns each word as array element. Keys are the index numbers of words
  1. Strip_tags() : To strip HTML of a string .
  2. Htmlspecialchars():  To stop the execution of html tags.
  3. Addslashes() : To add escape slashes (backslashes /) in front of single and double quotations.
  4. Stripslashes() : To remove the slashes , which we added with add slashes function ( addslashes())
  5. Str_replace() : To replace a string with the new string .
  6. Strchr() : To get substring of input string from specified characters .
  7. Strrchr(): Same as strchr(0 but it scarches the specified character from reverse direction of  string.
  8. Strstr() : It is same as strchr() , to get substring of a string from specified characters.
  9. Stristr() : same as strstr() but it is case insensitier.
  10. Similar_text() : To get no of similarities between two strings.
DATE & TIME FUNCTIONS

Time() :

  1. To get current date and  time information as time stamp value .  Time stamp is total no of seconds from 1970 jan 1 12:00am
  2. Date() : this function converts time stamp value as date, method and year format string.

Characters supported by date()

  • D : 2-digit date number with leading 0 .
  • J :  A number without leading ) (date number).
  • D : 3-characters day name (Mon, Tue, etc)
  • L : full day name .
  • m : month   no without  0.
  • n :  : month no without 0.
  • M : month name with 3-characters (Aug , sep, etc)
  • F : full month name .
  • y:  2-digit year  no.
  • y : 4-digit year no
  • h: 12-hour format with leading 0
  • H: 24-hour format with leading 0
  • g:  12-hour format without 0
  • G : 24 hour format without 0
  • i : minutes
  • s : seconds
  • a: lower case  am/pm.
  • A : upper case am/pm
  • w:  day no in a week from 0 to 6
  • N : day no a week from (1-7)
  • W: no of completed weeks in current year
  • e: country date  format , to get time zone of server .
  • p : to get GMT value  of server (%+5 :30)

Getdate() To get current  date and time information as array .
Checkdate(): To check input date is existent or not

Join Our WhatsApp Channel Join Now
Join Our Telegram Group Join Now