Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between php scalar data and array

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "what is the difference between php scalar data and array", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the difference between php scalar data and array" article.

The biggest difference is that a scalar can hold only one data, while an array can hold multiple data; and the scalar type is value passing, while the array is reference passing. In PHP, there are four types of scalar data: Boolean, string, integer, and floating point, which can only store one value at a time, while an array is a collection of data that can store any number of data of any type.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The difference between php scalar data and array

The biggest difference: a scalar can hold only one data, while an array can hold multiple data.

Other differences: scalar types are value passing, while arrays are reference passing.

What is scalar data?

The scalar data type is the most basic unit of the data structure and can only store one data. There are four types of scalar data in PHP:

Type function boolean (Boolean) the simplest data type, only two values: true (true) / false (false) string (string) string is a continuous sequence of characters integer (integer) integer data type contains all integers, it can be integer or negative float (floating point) floating point data type is also used to store numbers, unlike integers, it contains decimals

1) Boolean (boolean)

Boolean is one of the most commonly used data types in PHP, which saves a true value (true) or a false value (false).

/ / Code: $a = true; / / True $b = false; / / false

2) string (string)

A string is a continuous sequence of characters, consisting of numbers, letters, and symbols. Each character of a string occupies only one byte. Characters contain the following types

Character type name content numeric type such as: 1, 2, 3 alphanumeric type such as: a, b, c and other special types such as #, $, ^, & invisible types such as:\ n (newline character),\ r (carriage return),\ t (tab character), etc.

Invisible characters are special characters used to control the output of the string format, which is not visible in the browser, but the output of the string can be seen.

There are three ways to define strings in PHP:

a. Single quotation marks (')

$a ='zZ likes eating food'

b. Double quotes (")

B = "zZ loves food"

The difference between single quotation marks and double quotation marks: the variables contained in double quotation marks are automatically replaced with actual values, while the variables contained in single quotation marks are output as normal types. For example:

$a = 'hello';$b =' $a china';$c = "$a world"; / / it is recommended to write as follows: $c = "{$a} world"; not easily ambiguous echo $bbombecho $c; result: $a chinahello world

c. Delimiter (

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report