Is array a scalar type in php?

WBOY
Release: 2023-03-16 15:36:01
Original
1566 people have browsed it

Arrays are not scalar data types in PHP, arrays are composite data types; scalar data types mean that a scalar can only store one data, and arrays can store multiple data, so arrays are not scalar data types, composite data Types allow multiple data of the same type to be aggregated and represented as one entity item.

Is array a scalar type in php?

The operating environment of this article: Windows 10 system, PHP version 8.1, Dell G3 computer

Is array a scalar type in php

The array is not a scalar data type in PHP, the array is a composite data type

The scalar data type can only store one data, but any data can be stored in the array multiple data.

Composite data typeAllows multiple data of the same type to be aggregated together and represented as an entity item; composite data types include arrays (Array) and objects (Object).

PHP’s data types can be divided into three major categories, namely basic data types (scalar data types), composite data types and special data types.

Basic data type (scalar data type)

Basic data type (scalar data type) is the most basic unit of the data structure and can only store one piece of data. There are four types of scalar data types in PHP, as shown in the following table:

Is array a scalar type in php?

1. Boolean

Boolean is one of the more commonly used data types in PHP. It stores a true value or false value, where true and false are internal keywords of PHP. To set a Boolean variable, just assign true or false to the variable. In PHP, not only boolean values ​​are false, but non-boolean values ​​are also considered false in some special cases. For example, 0, empty string and just declare array without assignment.

2. String type (string)

A string is a continuous sequence of strings, consisting of numbers, letters and symbols. Each character in the string takes up only one byte. There are three ways to define strings, single quotes, double quotes, and delimiters (

Variables contained in backticks are output as ordinary characters, such as $i=' I'm the best', echo '$i' will output $i and double quotes will parse the variable and output "I'm the best"!

The sample code is as follows:

<?php
    //双引号方式声明字符串
    $str1 = "PHP中文网";  
    //单引号方式声明字符串
    $str2 = &#39;PHP 教程&#39;;      
    //Heredoc 方式声明字符串
    $str3 = <<<EOF
    url:
    https://www.php.cn/
EOF;
    echo $str1."<br>".$str2."<br>".$str3;
?>
Copy after login

The running results are as follows:

PHP中文网
PHP 教程
url: https://www.php.cn/
Copy after login

3. Integer (integer)

Integer data The type can only contain integers.

In PHP, integer variables are called integer or int types, which are used to represent an integer. The rules for integers are as follows:

The integer type must have at least one number (0~ 9);

The integer type cannot contain commas or spaces;

The integer type cannot contain the decimal point;

The integer type can be a positive or negative number.

The value range of the integer must be between -2E31 and 2E31, and can be expressed in three formats, namely decimal, hexadecimal (prefixed with 0x) and octal (prefixed with 0 ).

<?php
    $x = 5985;      // 定义一个整型数据类型的变量
    var_dump($x);   // 输出此变量
    echo "<br>";
    $x = -345;
    var_dump($x);   
    echo "<br>";
    $x = 0x8C;      //十六进制数字
    var_dump($x); 
    echo "<br>";
    $x = 047;       //八进制数字
    var_dump($x);
?>
Copy after login

Run the above code, the results are as follows:

int(5985)
int(-345)
int(140)
int(39)
Copy after login

4. Floating point type (float)

Floating point data types can be used Stores integers and decimals.

Floating point type is called float type in PHP, also known as real number. It can be used to store integers and decimals. The valid value range is between 1.8E-308 and 1.8E 308. Floating point numbers have higher precision than integer data types.

The sample code is as follows:

<?php
    $num1 = 10.365;
    $num2 = 2.4e3;
    $num3 = 8E-5;
    var_dump($num1, $num2, $num3);
?>
Copy after login

The running results are as follows:

float(10.365) float(2400) float(8.0E-5)
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Is array a scalar type in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template