首页 / PHP / ListandEachinPHP
ListandEachinPHP
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ListandEachinPHP,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1720字,纯文字阅读大概需要3分钟。
内容图文
List>>>>>>>>>>>>>>>>>>>>>>>>Sometimes it is very convienent way to do the continual assign,
ruby:
1 a,b,c,d = 1, 2, 3, 4;
php:
1 list($width, $height, $type, $attr) = getImageSize($img);
list() only works on base of a number indexed array, we can use empty variable to
jump over the unwished value, such as:
1 $info = array('coffee', 'brown', 'caffeine');2 list($drink, , $power) = $info;
Extra elements are assigned NULL in list;
Because list need an numbered array to gain values, when there is an hash array, you
need to do some work to get right numbered array, such as array_values or array_keys;
list() construct can be used within other list() constructs, such as
1 $matrix = array(array(1,2), array(3,4));2 list(list($a,$b), list($c, $d)) = $matrix;
List also can be used to swap values between variables without using an intermediary,
such as:
1 list($big, $small) = array($small, $big)
this can be done no mater how many variables there are. In ruby we do it just on this
simply way
1 a, b = b, a;
Each>>>>>>>>>>>>>>>>>>>>>>>>
Each() iterate an array key=>value, return an 4 sized array, using 0 and key to refer
original key, using 1 and value to refer original value.
You have to use reset before you begin iterator an array or after you finish iterate in
order to make the array pointer reset to the 0th element in array.
Usually each and list are combined to iterate an array in turns untill there are no
elements anymore. such as:
1 $fruit = array('a'=>'apple', 'b'=>'banana', 'c'=>'cranberry');2 reset($fruit);3 while(list($key, $val) = each($fruit))4 {5 echo "$key => $value\n";6 }
内容总结
以上是互联网集市为您收集整理的ListandEachinPHP全部内容,希望文章能够帮你解决ListandEachinPHP所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。