php向list数组中增加值的方法

作者:袖梨 2022-06-24

例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);
   //print_r($ffff);
  
   $value['flower']=$ffff['flower'];
   $value['likes']=$ffff['likes'];
  }

例子 2,array_push() 函数

 代码如下 复制代码

$a=array("Dog","Cat");
array_push($a,"Horse","Bird");
print_r($a);
?>

输出:

Array ( [0] => Dog [1] => Cat [2] => Horse [3] => Bird )

例子 3
带有字符串键的数组:

 代码如下 复制代码

$a=array("a"=>"Dog","b"=>"Cat");
array_push($a,"Horse","Bird");
print_r($a);
?>

输出:

Array ( [a] => Dog [b] => Cat [0] => Horse [1] => Bird )

相关文章

精彩推荐