Study Notes on PHP Data Types_PHP Tutorial
There are 8 scalar types in PHP, including string (string), integer (integer), float (floating point type, also called double), boolean (Boolean type) and composite types and resources (resources) ), NULL (empty), let’s take a look below.
php data type
PHP supports eight primitive types (type).
4 scalar types:
string (string), integer (integer), float (floating point type, also called double), boolean (Boolean type)
Two compound types:
array(array), object(object)
Two special types:
resource(resource), NULL(empty)
Boolean
Syntax: To specify a Boolean value, use the keywords TRUE or FALSE. Both are case-insensitive.
When converted to boolean, the following values are considered FALSE:
1> Boolean value FALSE
2> Integer value 0 (zero)
3> Floating point value 0.0 (zero)
4> Blank string and string “0″
5> Array without member variables
6> Object without unit
7> Special type NULL (including variables that have not been set)
All other values are considered TRUE (including any resources).
Note: -1, like other non-zero values (whether positive or negative), is considered TRUE!
================================================== ==================================
Shape(integer)
Syntax: Integer values can be specified in decimal, hexadecimal or octal notation, preceded by an optional sign (- or +).
If you use octal notation, you must add 0 (zero) before the number, and if you use hexadecimal notation, you must add 0x before the number.
================================================== ===================================
string(string)
Three ways to define: single quotes, double quotes, delimiters.
String conversion:
You can convert a value to a string using the (string) notation or the strval() function.
The Boolean value TRUE will be converted to the string "1", while the value FALSE will be represented as "" (i.e. the empty string).
NULL will be converted to an empty string.
Convert string to numeric value
When a string is evaluated as a number, the following rules determine the type and value of the result.
If it contains any of the ".", "e" or "E" characters, the string is evaluated as a float. Otherwise it is treated as an integer. As shown below:
The code is as follows
|
Copy code
|
||||
$foo = 1 + “10.5″; // $foo is float (11.5)
$foo = 1 + “-1.3e3″; // $foo is float (-1299)
$foo = 1 + “bob-1.3e3″; // $foo is integer (1) | ================================================== ======================================

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
