PHP-001- [] array - the array defined and simple traversal

Learning Points

  1. Data definition
  2. Key type
  3. Common type
  4. Custom key type
<?php
// 数组的定义:键值类型
$one = array(
    "a" => "213",
    "b6" => "789",
    "c" => "ddd",
    "d" => "dd"
);
// 可以展示出数组的结构
print_r($one); 
echo "<hr />";

// 数组的定义:普通类型
$two = array(
    1,
    2,
    3,
    4,
    5,
    6
); // 不指定key的话将会从整数0开始
print_r($two);
echo "<hr />";

// 数组的定义:自定义键值类型
$three = array(
    3 => "213",
    4,
    96,
    3
); // 后续的键名将会自动的添加
print_r($three);
echo "<hr />";

//数据简单遍历
foreach ($one as $item)
{
    echo $item;
    echo "<br />";
}
?>

 

Published 47 original articles · won praise 3 · Views 1964

Guess you like

Origin blog.csdn.net/yueyekonglong/article/details/103988391