python,java,php中的foreach

<?php
// python中的for遍历:
/*
for num in num_list:
	print(num)
*/

// java中的foreach:
/*
ArrayList<int> list = new ArrayList<int>();
list.add(1);
list.add(2);
list.add(3);
for(int i : list){
	System.out.println(i);
}
*/

// php中的foreach:
$a = array('name'=>'张三','age'=>30,'gender'=>'男');
foreach($a as $k=>$v){
	echo $k,':',$v,'<br/>';
}
?>

猜你喜欢

转载自blog.csdn.net/zhu6201976/article/details/89412993