文章是一个简单应用实例利用foreach遍历数组,然后给数组增加一些值进去了,方法比较简单,本文章后来介绍了直接使用array_push 来给数组增加值两者本人更喜欢后者一些.
例1代码如下:
- foreach($list as &$value){
-
- if(isOnline($value['uid'])){
- $value['sid'] = '1';
-
- }else{
- $value['sid'] = '0';
- }
- $value['likes']='1';
- $sql="SELECT uid,likes,flower FROM ".DB::table("dmember_member_count")." WHERE uid='".$value['uid']."'";
- $fff = DB::query($sql);
- $ffff = DB::fetch($fff);
-
-
- $value['flower']=$ffff['flower'];
- $value['likes']=$ffff['likes'];
- }
例子 2,array_push()函数代码如下:
- <?php
- $a=array("Dog","Cat");
- array_push($a,"Horse","Bird");
- print_r($a);
- ?>
-
-
例子 3,带有字符串键的数组,代码如下:
- <?php
- $a=array("a"=>"Dog","b"=>"Cat");
- array_push($a,"Horse","Bird");
- print_r($a);
- ?>
-
-