Home >Backend Development >PHP Tutorial >php-PHP中使用foreach和while each输出关联数组,只能显示其中一个

php-PHP中使用foreach和while each输出关联数组,只能显示其中一个

WBOY
WBOYOriginal
2016-06-02 11:33:561004browse

phpforeach

$prices = array( 'Tires'=>100 );

$prices[ 'Oil' ] = 10;

$prices[ 'Spark plugs' ] = 4;

<code>echo $prices['Oil'].'<br>';foreach ($prices as $key => $value) {    echo $key.' - '.$value.'<br>';    }while($element = each($prices)){    echo $element[ 'key' ];    echo ' - ';    echo $element[ 'value' ];    echo '<br>';}</code>

?>

注释掉两种输出方式中的任何一个,另一个都可以正常输出;
但是把它们放在一起后,却只能输出其中一个。
然而, 我把两种输出方式的顺序调转后,发现两个都可以输出。
请问,何解?

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