开发者

Array Question in PHP

As I know, I can define an array in PHP.

$input = array("red", "green", "blue", "yellow");

But how can I

foreach ($query->result() a开发者_C百科s $row)
{
   insert each of $row member to $input ?
}


You can do that easily this way

foreach ($query->result() as $row)
{
   $input[] = $row;
}


You can do it in one time if im correct:

$input = array_merge($input, $query->result());

if you want to change something in the result from you query you have to do it as the way other answers do.

EDIT:

if(gettype($query->result()) == "array")
{
    $input = array_merge($input, $query->result());
}
else
{
    // if it is a object its changed to array
    $input = array_merge($input, (array)$query->result());
}


foreach ($query->result() as $row)
{
  $input[] = $row;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜