亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取數組中的每個用戶列表

如何獲取數組中的每個用戶列表

PHP
森林海 2021-09-05 14:09:05
public function getChildren($parent, $level=0,$getlevel=array()) {     $criteria = new CDbCriteria;    $criteria->condition='referred_by_user_id=:id';    $criteria->params=array(':id'=>$parent);    $count = array(0=>0);    $model = $this->findAll($criteria);    // $levelcount = array();    $user=User::model()->findbypk(Yii::app()->user->id);    if($user->level!=$level)    {         foreach ($model as $key) {            $count[0]++;                        $index=1;            // echo str_repeat(' — ', $level) . $key->name . "<br />";            $children= $this->getChildren($key->id, $level+1);            // pr($children);die;            foreach ($children as $child)            {                // pr($child);                if ($child==0)                  continue;                if (isset($count[$index]))                  $count[$index] += $child;                else                      $count[$index] = $child;                $index++;            }        }    }   return $count; }我只能輸出用戶數。如何獲取數組中每個級別的用戶 ID?
查看完整描述

2 回答

?
慕仙森

TA貢獻1827條經驗 獲得超8個贊

我認為問題是你必須在 for 之外創建 $index 變量


查看完整回答
反對 回復 2021-09-05
?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

我前段時間做了類似的事情:


public static function getChildren($idParent) {

    $elem      = [];

    $childrens = Arbol::model()->findAll("estado = 1 and id_parent = " . $idParent . ' ORDER BY level');

    foreach ($childrens as $key => $child) {

        $persona = Persona::model()->findbyPk($child->id_child);

        if ((int) $persona->id_superior === $idParent) {

            $nombre     = explode(" ", $persona->nombres);

            $elem[$key] = [

                "id"    => $persona->id_persona,

                "image" => Yii::app()->baseUrl . '/images/user-icon' . ($persona->pago_inscripcion ? '-activo.png' : '.png'),

                "text"  => [

                    'title' => $nombre[0] . ' ' . substr($persona->apellido_paterno, 0, 1) . '.'

                ]

            ];

        } else {

            $keySUperior = array_search($persona->id_superior, array_column($elem, "id"));

            if (is_int($keySUperior)) {

                $elem[$keySUperior]["children"] = self::getChildren((int) $persona->id_superior);

            }

        }

    }


    return $elem;

}

我希望我能給你任何幫助


查看完整回答
反對 回復 2021-09-05
  • 2 回答
  • 0 關注
  • 148 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號