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

WBOY
Release: 2016-06-02 11:33:56
Original
958 people have browsed it

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>
Copy after login

?>

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!