开发者

How to arrange the obtained result's Array given Below, to get a desired result given below?

I Have a query

SELECT classid, COUNT(*) as cnt FROM tbl_name GROUP BY classid

on Table

| id | classid | contextid |

  1       1           2
  2       1           1
  3       2           1
  4       1           1

this will yields me the result by the use of an inbuilt library function moodle as

Array
(
    [1] => stdClass Object
        (
            [classid] => 1
            [classcnts]开发者_StackOverflow社区 => 3
        )

    [2] => stdClass Object
        (
            [classid] => 2
            [classcnts] => 1
        )

)

I need the result in an array in the form of

Array(
     [classid]=>[classcnts]

)

i.e

Array(
     1=>3,
     2=>1
)

So how can i arrange the available array to find the required array.

I am working in PHP

Thanks


try:

foreach($arr as $k){
   $new[$k->classid] = $k->classcnts
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜