开发者

how to assign elements of one array to another array in php

i retrieved data from my开发者_如何学Csql table in php


  $array2=array(); while($q1=  mysql_fetch_assoc($result))
{    print_r($q1);
    $array2[]= $q['user_id'];
}

the print_r($q1) will output this

Array ( [user_id] => 1 ) Array ( [user_id] => 2 ) Array ( [user_id] => 4 ) 
. Now i want to assign these values into another array i.e
 $array2[]=$q['user_id'];
but when i echo $array2 this gives me result otherthan $print_r($q) i.e

Array ( [0] => [1] => [2] => ) 

my question is how can i get the value of [user_id]=>4 from this array


$q is different from $q1..

You need:

$array2[]= $q1['user_id'];

It should actually be throwing a warning about $q['user_id'] not being defined. Do you have error reporting turned on?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜