给数组增加元素_PHP
时间:2021-07-01 10:21:17
帮助过:1人阅读
给数组增加元素
$Cities[] = "北京"; //等同于$Cities[0] = "北京"
$Cities[] = "天津"; //等同于$Cities[1] = "天津"
$Cities[] = "上海"; //等同于$Cities[2] = "上海"
$Cities[] = "深圳"; //等同于$Cities[3] = "深圳"
/*
** 统计元素个数
*/
$indexLimit = count($Cities); //把数组中元素的个数赋给$indexLimit
/*
** 打印所有数组
*/
for($index=0; $index < $indexLimit; $index++)
{
print("第 $index 个城市是 $Cities[$index]。
\n");
}
?>