【PHP】PHP数组:PHP 7中的一维数组、多维数组、关联数组及对象数组(1)


写在前面的话

最近在学习PHP的过程中看到了这本英文版的书,主要针对PHP中各种数组的使用进行讲解,觉得还不错,决定翻译出来供大家一起学习讨论。

因水平有限,翻译时附上原文,欢迎批评指正!

注意:

翻译时为了尊重原著,并兼顾文章结构。

标题部分采用中文在前后附上英文,文中各段落英文在前,下一段落为中文译文。

PHP Arrays:Single, Multi-dimensional, Associative and Object Arrays in PHP 7

PHP数组:PHP 7中的一维数组、多维数组、关联数组及对象数组

—Steve Prettyman

Apress出版社,2017年出版

引言 Introduction

PHP Arrays: Single, Multidimensional, Associative, and Object Arrays in PHP 7 is intended for use as a supplemental beginning-level programming book. It is not the goal of this book to cover advanced techniques in the current versions of the PHP programming language. Some beginning knowledge of general PHP programming concepts is expected but no actual programming experience or education is assumed.

PHP Arrays: Single, Multidimensional, Associative, and Object Arrays in PHP 7 是给入门级编程人员使用的补充性书籍。本书并不涵盖PHP 7编程语言的高级技巧。读者最好具有一些PHP编程的一般概念和知识,但并不要求读者具备实际编程经验或是接受过相关培训。

All code examples in this book are compatible with PHP 7. The newest methods (functions) available in PHP have been used to provide the reader with the most current coding techniques. The examples use core methods provided in the PHP language. PHP includes many additional methods to accomplish similar tasks as shown within. The reader may, and should, research additional advanced array techniques after understanding the material presented in this book.

本书所有代码示例在PHP 7中是兼容的。书中使用了PHP中的最新方法(函数),使读者获得当前最新的编程技巧。代码示例使用的是PHP语言中的核心方法。PHP包含了许多额外方法,以完成本书示例中演示的类似任务。在掌握本书所提供的材料后,读者可以去也应该去更加深入地研究PHP数组应用的高级技巧。

给教师的特别提示 Special Note—Teachers

This book is provided as a supplementary guide to introductory textbooks on PHP 7. The intent of this book is to provide additional examples and explanation of the power and use of arrays in the PHP language. PHP arrays provide many capabilities that arrays in other languages do not provide.

本书作为PHP 7入门教科书的补充性手册,目的在于提供一些额外的范例和解析,以说明PHP数组的强大之处及其用法。PHP数组提供了许多其它语言中数组所没有的功能。

Teaching tools, including test banks, course outline, and PowerPoint slides are available as part of the source code download available at the Apress website.

在Apress网站下载的源代码包含了一些教学工具,包括测试库、课程大纲和PowerPoint幻灯片。

代码示例、图片及链接 Code Examples, Images, and Links

Every effort has been made to catch any errors in code (and grammar). Please let us know if/when you discover problems in this book. Please send all corrections to Steve Prettyman (steve_prettyman@hotmail.com).

我们已经尽力去发现代码(和语法)中的错误。如果您在书中发现任何问题,请联系我们。您可以把修正内容发送至Steve Prettyman (steve_prettyman@hotmail.com)。

All code examples, images, and links are available for download from the following location. Please download code examples from the website. Copying code from the book may cause errors due to format requirements for publishing.

所有代码示例、图片及链接都可以从下面给出的链接中下载。请从网站上下载代码示例,因为出版的格式需要,直接从书中复制代码可能会导致错误。

www.apress.com/9781484225554

第1章 PHP 7 基础

CHAPTER 1 PHP 7 Basics

After completing this chapter, the student will be able to…

  • Create a simple error-free PHP program
  • Understand the use and value of conditional statements
  • Understand the use and value of for, while, and foreach loops
  • Understand the use and value of functions
  • Understand the use and value of arrays
  • Understand the basic structure of an object-oriented PHP program

完成本章学习后,您将可以:

  • 创建一个没有任何错误的PHP程序
  • 理解条件语句的用法和使用场景
  • 理解 for、while 和 foreach 循环的用法和使用场景
  • 理解函数的用法和使用场景
  • 理解数组的用法和使用场景
  • 理解面向对象PHP程序的基本结构

1.1 安装 Installation

The PHP environment can be installed on almost any operating system. This allows the developer the ability to easily create a development and testing environment. Complete testing can and should be completed before the code is installed in a live environment. The developer should determine the major PHP version used in the live environment and replicate this same version in the test environment.
PHP环境几乎可以安装到任何操作系统上,这使得开发人员能够很轻易地创建开发和测试环境。代码部署到生产环境中之前应该经过完整测试。开发人员应决定在生产环境中使用的PHP版本,然后在测试环境中使用相同的PHP版本。

PHP 7 includes many new tools and has removed some tools from previous versions. Therefore, it is imperative that both the live environment and the testing environment be the same. The testing environment can also be used to test minor release changes on existing code before the live environment is upgraded to the new release.
PHP 7 引入了许多新方法,同时也删除了一些旧版本里支持的方法。因此,必须保持测试环境和生产环境中的版本一致。在生产环境更新到最新版本前,测试环境也可以用来在已有代码上测试副版本变化。

Although PHP can be installed by itself, novice and less experienced programmers should use one of the many installation tools available to install PHP with Apache Server, MySQL, PhpAdmin, and other related applications. These packages greatly simplify the process and are free and open source. Installing PHP separately requires a more in-depth knowledge of what versions of tools are compatible and changes required to the configuration files to link these tools together.
尽管PHP可以单独安装,但对于新手或经验不足的编程人员还是建议使用一些安装工具,在安装PHP的同时一并把Apache服务器、MySQL、PhpAdmin等其它相关应用也安装好。这些安装工具极大地简化了安装过程,而且是开源免费的。单独安装PHP需要考虑不同工具之间的版本兼容问题,还需要更改相关配置文件来联接它们。

Apache, which is open source and free, is the most common server to use with PHP. However, PHP can be used with other servers, including Microsoft’s Web Server. It is beyond the scope of this book to look at other servers. However, you can find installation information on the Internet.

Apache是一种开源免费的服务器,经常与PHP搭配使用。当然,PHP也可以与其它服务器搭配,包括微软的Web服务器。有关其它服务器的安装已超出本书讨论范围,相关信息可以上网查询。

MySQL, which is also open source and free, is the most common database used with PHP. PHP has the ability to use other databases, including Oracle and SQL Server among others. In many cases, the coding used to manipulate MySQL databases is very similar to the code used to manipulate other databases. php.net includes some basic information on drivers and coding for non-MySQL databases. You can also find additional information on the database’s websites. PhpAdmin is a free tool to easily create and update MySQL database information. As stated before, most packages include a version of this software.

MySQL也是开源免费的,是最常与PHP搭配使用的数据库管理软件。PHP也可以使用其它数据库,包括Oracle、SQL Server等。通常情况下,操作MySQL的代码与操作其它数据库的代码是极其类似的。php.net网站上提供了有关非MySQL数据库的一些驱动和编码信息,更多信息可以到数据库网站上查找。利用PhpAdmin这一免费工具可以轻松创建和更新MySQL数据库信息。如前所述,大部分都会包含PhpAdmin软件。

LAMP (Linux, Apache, MySQL, PHP), MAMP (Mac, Apache, MySQL, PHP), and WAMP (Windows, Apache, MySQL, PHP) package versions are readily available on the web. There are many organizations that currently create similar packages. We will briefly look at one of them. However, you will find that they all work in a similar way.

在网上可以找到适用于不同操作系统的安装包:LAMP (Linux系统、Apache、MySQL、PHP)、MAMP (Mac系统、Apache、MySQL、PHP) 和 WAMP (Windows系统、Apache、MySQL、PHP)。现在有很多组织都在制作这种安装包,我们会挑一种简单看看,您会发现它们用起来都差不多。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iShare_123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值