php数组中添加数组_了解PHP中的数组

php数组中添加数组

An array is a systemic arrangement of objects. Hum, what does this mean? Well in programming an array is a type of data structure. Each array can hold several pieces of information. It’s sort of like a variable in that it stores data, but not at all like a variable in that instead of storing one bit of information it can store many pieces of information.

数组是对象的系统排列。 哼,这是什么意思? 在数组编程中,好是一种数据结构。 每个阵列可以容纳几条信息。 它有点像变量,它存储数据,但根本不像变量,因为它不存储一点信息,而是可以存储许多信息。

Let’s start with an example. Let’s say that you are storing information about people. You could have a variable that stored my name “Angela”. But in an array, you could store my name, my age, my height, my

让我们从一个例子开始。 假设您要存储有关人的信息。 您可能有一个变量,该变量存储了我的名字“ Angela”。 但是在数组中,您可以存储我的姓名,年龄,身高,

In this sample code, we will look at storing two bits of information at a time, the first being somebody’s name and the second being their favorite color.

在此示例代码中,我们将查看一次存储两位信息,第一个是某人的名字,第二个是他们最喜欢的颜色。

In this example code, you can see that the friend array is sorted by number, and contains a list of friends. In the second array, color, instead of using numbers it uses strings to identify the different bits of information.

在此示例代码中,您可以看到friend数组按数字排序,并包含一个好友列表。 在第二个数组中,颜色不是使用数字,而是使用字符串来标识信息的不同位。

The identifier used to retrieve data from the array is called it’s key. In our first example, the keys were integers 0, 1, 2, and 3. In our second example, the keys were strings. In both cases, we are able to access the data held in the array by using both the array’s name, and the key.

用于从数组中检索数据的标识符称为密钥。 在我们的第一个示例中,键是整数0、1、2和3。在我们的第二个示例中,键是字符串。 在这两种情况下,我们都可以使用数组的名称和键来访问数组中保存的数据。

Like variables, arrays always start with a dollar sign ($array) and they are case sensitive. They can not start with an underscore or a number, you must start them with a letter.

像变量一样,数组始终以美元符号($ array)开头,并且区分大小写。 它们不能以下划线或数字开头,必须以字母开头。

So, to put it simply, an array is kind of like a variable with lots of little variables inside of it. But what exactly do you do with an array? And how is it useful to you as a PHP programmer?

因此,简单地说,数组有点像一个变量,里面有很多小变量。 但是,您到底对数组做什么? 作为PHP程序员,它对您有什么用?

In practice, you will probably never create an array like the one in the example above. The most useful thing you can do with an array in PHP is to use it to hold information you get form somewhere else.

实际上,您可能永远不会像上面的示例那样创建一个数组。 您可以使用PHP中的数组做的最有用的事情是使用它来保存从其他地方获取的信息。

Having your website's information stored in an MySQL database is not uncommon. When your website needs certain information it simply accesses your database, and wha-laa, on demand data.

将您的网站信息存储在MySQL数据库中并不少见。 当您的网站需要某些信息时,它只需访问您的数据库,以及按需数据。

Let’s say you have a database of people who live in your city. You now want to search that database and print out records for anyone named “Tom”. How would you go about doing this?

假设您有一个城市居民的数据库。 现在,您要搜索该数据库并打印出名为“ Tom”的任何人的记录。 您将如何去做?

You would read through the database for people named Tom, and then pull their name and all the other information about them from the database, and place it in an array inside of your program. You are then able to cycle through this array, and print out the information or store it to use elsewhere in your program.

您将通读名为Tom的人员的数据库,然后从数据库中提取其姓名和所有其他有关他们的信息,并将其放在程序内部的数组中。 然后,您可以循环浏览此数组,并打印出信息或将其存储以在程序的其他地方使用。

On the surface, an array might not look that interesting to you, but when you do more programming and start storing more complex data structures you will find you are often writing them to arrays when they need to be used.

从表面上看,数组对您来说似乎并不那么有趣,但是当您进行更多的编程并开始存储更复杂的数据结构时,您会发现您经常在需要使用它们时将它们写入数组。

翻译自: https://www.thoughtco.com/understanding-arrays-in-php-2693906

php数组中添加数组

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值