PHP学习笔记-数组(1),php学习笔记数组
1-1 数组定义
1.什么是数组?
所谓数组,就是相同数据类型的元素按一定顺序排列的集合,就是把有限个类型相同的变量用一个名字命名,然后用编号区分他们的变量的集合,这个名字称为数组名,编号称为下标。组成数组的各个变量称为数组的分量,也称为数组的元素,有时也称为下标变量。
语法如下:
<?<span>php </span><span>//</span><span>设置某个变量为一个空数组</span> <span>$arr</span>=<span>array</span><span>(); </span>?>
1-2 索引数组初始化
PHP有两种数组:索引数组、关联数组。
索引和关联两个词都是针对数组的键而言的。
索引数组是指数组的键是整数的数组,并且键的整数顺序是从0开始,依次类推。
<?<span>php </span><span>$num</span>=<span>array</span>(1,2,3<span>); </span><span>print_r</span>(<span>$num</span>[0<span>]); </span>?>
输出结果:1
1-3 索引数组赋值
3种方法
<?<span>php </span><span>$arr</span>[0]=1;<span>//</span><span>方法1</span> <span>$arr</span>=<span>array</span>('0'=>1);<span>//</span><span>方法2</span> <span>$arr</span>=<span>array</span>(1);<span>//</span><span>方法3</span> ?>
1-4 访问数组内容
<?<span>php </span><span>//</span><span>从数组变量$arr中,读取键为0的值</span> <span>$arr</span> = <span>array</span>(1,2,3<span>); </span><span>$arr0</span>=<span>$arr</span>[0<span>]; </span><span>echo</span> <span>$arr0</span><span>; </span>?>

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
