这段PHP代码通过两种不同的方式创建PHP数组,并通过foreach语句分别遍历两个数组输出
/**
* PHP通过两种不同的方式创建数组并遍历数组的代码
*
* @param
* @arrange 512-笔记网: 512Pic.com
**/
/* First method to create array. */
$numbers = array( 1,2,3,4,5);
foreach( $numbers as $value )
{
echo "Value is $value <br />";
}
/* Second method to create array. */
$numbers[0] = "one";
$numbers[1] = "two";
$numbers[2] = "three";
$numbers[3] = "four";
$numbers[4] = "five";
foreach( $numbers as $value )
{
echo "Value is $value <br />";
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
输出结果如下 Value is 1 Value is 2 Value is 3 Value is 4 Value is 5 Value is one Value is two Value is three Value is four Value is five 原文链接:https://www.f2er.com/php/528284.html