php数组如何实现循环队列
展开全部
1.PHP基本上就是一种数组语言。时常要进行大量的数组循环操作,主要有两种方式,
一种是foreach,另一种是while,
代码如下:
foreach ($array as $value) {
echo $value;
}
while (list($key) = each($array)) {
echo $array[$key];
}
foreach ($array as $value) {
echo $value;
}
while (list($key) = each($array)) {
echo $array[$key];
}
2.在循环里进行的是数组“写”操作,则while比foreach快:
foreach ($array as $key => $value) {
echo $array[$key] = $value . '...';
}
while (list($key) = each($array)) {
$array[$key] = $array[$key] . '...';
}
foreach ($array as $key => $value) {
echo $array[$key] = $value . '...';
}
while (list($key) = each($array)) {
$array[$key] = $array[$key] . '...';
}
一种是foreach,另一种是while,
代码如下:
foreach ($array as $value) {
echo $value;
}
while (list($key) = each($array)) {
echo $array[$key];
}
foreach ($array as $value) {
echo $value;
}
while (list($key) = each($array)) {
echo $array[$key];
}
2.在循环里进行的是数组“写”操作,则while比foreach快:
foreach ($array as $key => $value) {
echo $array[$key] = $value . '...';
}
while (list($key) = each($array)) {
$array[$key] = $array[$key] . '...';
}
foreach ($array as $key => $value) {
echo $array[$key] = $value . '...';
}
while (list($key) = each($array)) {
$array[$key] = $array[$key] . '...';
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询