i

PHP Tutorial

PHP Data Types

In PHP, we work with all types of information, and when we write some complex programs and functions, we will deal with different types of data and information. So, let us discuss different types of data we can work with the php script and program, and we can represent inside the php code. 

PHP supports below data types. 

  • String – It is plain text such as name, location, book etc. Use open and closed quotation marks whenever you are working with string. E.g. $phrase =" Be what you are”.

  • Numbers – Numbers can be two types, i.e. an integer and decimal numbers. Integer will be a whole number such as $age = 30; for integers and $cga = 78.9; for floating numbers.

  • Boolean – Boolean is a true or false value. Many times, while programming, we need to work with true or false values, and hence, we use the variables with Boolean type. For e.g. $IsMale = true;

  • NULL – Whenever a variable has no value assigned to it or created without a value, it will have Null value. 

  • Arrays – Arrays are used when we want a collection of values in an indexed way, and a single variable can store multiple values using arrays. E.g. $Weekday = array("Monday"," Tuesday"," Wednesday"," Thursday"," Friday");

  • Objects – Object is an instance of a class, and it can have values and functions specified to any class, and it should be declared. Object defines information on how to process the data or data itself.

  • Resources – It is not the actual data type, but it stores the references to the resources and functions that are outside PHP such as database connections.