Home >Backend Development >PHP Tutorial >给数组增加元素_PHP

给数组增加元素_PHP

WBOY
WBOYOriginal
2016-06-01 12:30:25857browse



给数组增加元素


 $Cities[] = "北京"; //等同于$Cities[0] = "北京"
 $Cities[] = "天津"; //等同于$Cities[1] = "天津"
 $Cities[] = "上海"; //等同于$Cities[2] = "上海"
 $Cities[] = "深圳"; //等同于$Cities[3] = "深圳"
 /*
 ** 统计元素个数
 */
 $indexLimit = count($Cities); //把数组中元素的个数赋给$indexLimit
 /*
 ** 打印所有数组
 */
 for($index=0; $index  {
  print("第 $index 个城市是 $Cities[$index]。
\n");
 }
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:调用文本文件内容_PHPNext article:php 验证码程序_PHP