Ich habe ein Array aus einer Tabelle in der Datenbank abgerufen und es ausgeschnitten, um die Analyse zu erleichtern:
<code>$arr = array( 0 => array( 'uid' => 5, 'username' => '', 'password' => '', 'user_status' => 1, 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '13863810574', 'realname' => '汪精卫', 'level' => '普通会员', 'trade_account' => '568050269', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', ), 1 => array( 'uid' => '6', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18807556392', 'realname' => '周杰伦', 'level' => '普通会员', 'trade_account' => '12435356', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', ), 2 => array( 'uid' => '7', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18316850912', 'realname' => '奥巴马', 'level' => '普通会员', 'trade_account' => '83475535', 'reg_time' => null, 'recom_account' => '834755351', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', ), 3 => array( 'uid' => '8', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879126845', 'realname' => '大卫', 'level' => '普通会员', 'trade_account' => '834755351', 'reg_time' => null, 'recom_account' => '154548', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', ), 4 => array( 'uid' => '9', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '黄建', 'level' => '普通会员', 'trade_account' => '154548', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', ), 5 => array( 'uid' => '10', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '张科', 'level' => '普通会员', 'trade_account' => '9527', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', ), );</code>
Jetzt möchte ich dieses mehrdimensionale Array verarbeiten. Die Regel lautet: Wenn der Wert von recom_account von Schlüssel a gleich dem trade_account von Schlüssel b ist, dann ist das Schlüssel-Wert-Paar von a eine direkte Unterkategorie des Schlüssels -Wert-Paar von b. Wenn der recom_account von Schlüssel a gleich ist, ist das Schlüssel-Wert-Paar c eine indirekte Unterkategorie des Schlüssel-Wert-Paars (Kategorie). kann mehrere direkte Unterkategorien haben, entspricht aber nur einer direkten übergeordneten Kategorie, d. h. trade_account ist die einzige. Ja, recom_account ist nicht eindeutig. Das erwartete Rückgabeergebnis ist: Jedes Schlüssel-Wert-Paar fügt einen Zählschlüssel hinzu, dessen Wert die Anzahl aller direkten Unterkategorien ist, einen untergeordneten Listenschlüssel, dessen Wert ein mehrdimensionales Array ist, das alle Informationen der Unterkategorie aufzeichnet, und einen total_count-Schlüssel, dessen Wert ist Der Wert ist die Anzahl aller Unterkategorien. Ein Haschild-Feld von 1 gibt an, dass die Kategorie Unterkategorien hat (einschließlich direkter Unterkategorien und indirekter Unterkategorien), und ein Haschild-Feld von 0 gibt an, dass es keine Unterkategorien gibt. Wie im obigen Array wird erwartet, dass das folgende Format generiert wird.
$list = array(
<code> 0 => array( 'uid' => 5, 'username' => '', 'password' => '', 'user_status' => 1, 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '13863810574', 'realname' => '汪精卫', 'level' => '普通会员', 'trade_account' => '568050269', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => '2', 'total_count' => '4', 'childlist' => array( 9 => array(//9为子分类的uid 'uid' => '9', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '黄建', 'level' => '普通会员', 'trade_account' => '154548', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 1, 'total_count' => 2, 'childlist' => array( 8 => array( 'uid' => '8', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879126845', 'realname' => '大卫', 'level' => '普通会员', 'trade_account' => '834755351', 'reg_time' => null, 'recom_account' => '154548', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 1, 'total_count'=>1, 'childlist' => array( 7 => array(//7为子分类的uid 'uid' => '7', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18316850912', 'realname' => '奥巴马', 'level' => '普通会员', 'trade_account' => '83475535', 'reg_time' => null, 'recom_account' => '834755351', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ) ) ) ) ), 10 => array( 'uid' => '10', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '张科', 'level' => '普通会员', 'trade_account' => '9527', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), ) ), 1 => array( 'uid' => '6', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18807556392', 'realname' => '周杰伦', 'level' => '普通会员', 'trade_account' => '12435356', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 2 => array( 'uid' => '7', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18316850912', 'realname' => '奥巴马', 'level' => '普通会员', 'trade_account' => '83475535', 'reg_time' => null, 'recom_account' => '834755351', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 3 => array( 'uid' => '8', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879126845', 'realname' => '大卫', 'level' => '普通会员', 'trade_account' => '834755351', 'reg_time' => null, 'recom_account' => '154548', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 4 => array( 'uid' => '9', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '黄建', 'level' => '普通会员', 'trade_account' => '154548', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 5 => array( 'uid' => '10', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '张科', 'level' => '普通会员', 'trade_account' => '9527', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), ); </code>
Ich habe zum Debuggen auf http://www.thinkphp.cn/topic/... verwiesen, konnte aber den Rückgabewert nicht erhalten.
Ich habe ein Array aus einer Tabelle in der Datenbank abgerufen und es ausgeschnitten, um die Analyse zu erleichtern:
<code>$arr = array( 0 => array( 'uid' => 5, 'username' => '', 'password' => '', 'user_status' => 1, 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '13863810574', 'realname' => '汪精卫', 'level' => '普通会员', 'trade_account' => '568050269', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', ), 1 => array( 'uid' => '6', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18807556392', 'realname' => '周杰伦', 'level' => '普通会员', 'trade_account' => '12435356', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', ), 2 => array( 'uid' => '7', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18316850912', 'realname' => '奥巴马', 'level' => '普通会员', 'trade_account' => '83475535', 'reg_time' => null, 'recom_account' => '834755351', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', ), 3 => array( 'uid' => '8', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879126845', 'realname' => '大卫', 'level' => '普通会员', 'trade_account' => '834755351', 'reg_time' => null, 'recom_account' => '154548', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', ), 4 => array( 'uid' => '9', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '黄建', 'level' => '普通会员', 'trade_account' => '154548', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', ), 5 => array( 'uid' => '10', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '张科', 'level' => '普通会员', 'trade_account' => '9527', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', ), );</code>
Jetzt möchte ich dieses mehrdimensionale Array verarbeiten. Die Regel lautet: Wenn der Wert von recom_account von Schlüssel a gleich dem trade_account von Schlüssel b ist, dann ist das Schlüssel-Wert-Paar von a eine direkte Unterkategorie des Schlüssels -Wert-Paar von b. Wenn der recom_account von Schlüssel a gleich ist, ist das Schlüssel-Wert-Paar c eine indirekte Unterkategorie des Schlüssel-Wert-Paars (Kategorie). kann mehrere direkte Unterkategorien haben, entspricht aber nur einer direkten übergeordneten Kategorie, d. h. trade_account ist die einzige. Ja, recom_account ist nicht eindeutig. Das erwartete Rückgabeergebnis ist: Jedes Schlüssel-Wert-Paar fügt einen Zählschlüssel hinzu, dessen Wert die Anzahl aller direkten Unterkategorien ist, einen untergeordneten Listenschlüssel, dessen Wert ein mehrdimensionales Array ist, das alle Informationen der Unterkategorie aufzeichnet, und einen total_count-Schlüssel, dessen Wert ist Der Wert ist die Anzahl aller Unterkategorien. Ein Haschild-Feld von 1 gibt an, dass die Kategorie Unterkategorien hat (einschließlich direkter Unterkategorien und indirekter Unterkategorien), und ein Haschild-Feld von 0 gibt an, dass es keine Unterkategorien gibt. Wie im obigen Array wird erwartet, dass das folgende Format generiert wird.
$list = array(
<code> 0 => array( 'uid' => 5, 'username' => '', 'password' => '', 'user_status' => 1, 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '13863810574', 'realname' => '汪精卫', 'level' => '普通会员', 'trade_account' => '568050269', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => '2', 'total_count' => '4', 'childlist' => array( 9 => array(//9为子分类的uid 'uid' => '9', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '黄建', 'level' => '普通会员', 'trade_account' => '154548', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 1, 'total_count' => 2, 'childlist' => array( 8 => array( 'uid' => '8', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879126845', 'realname' => '大卫', 'level' => '普通会员', 'trade_account' => '834755351', 'reg_time' => null, 'recom_account' => '154548', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 1, 'total_count'=>1, 'childlist' => array( 7 => array(//7为子分类的uid 'uid' => '7', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18316850912', 'realname' => '奥巴马', 'level' => '普通会员', 'trade_account' => '83475535', 'reg_time' => null, 'recom_account' => '834755351', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ) ) ) ) ), 10 => array( 'uid' => '10', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '张科', 'level' => '普通会员', 'trade_account' => '9527', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), ) ), 1 => array( 'uid' => '6', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18807556392', 'realname' => '周杰伦', 'level' => '普通会员', 'trade_account' => '12435356', 'reg_time' => null, 'recom_account' => '243556', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 2 => array( 'uid' => '7', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18316850912', 'realname' => '奥巴马', 'level' => '普通会员', 'trade_account' => '83475535', 'reg_time' => null, 'recom_account' => '834755351', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 3 => array( 'uid' => '8', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879126845', 'realname' => '大卫', 'level' => '普通会员', 'trade_account' => '834755351', 'reg_time' => null, 'recom_account' => '154548', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 4 => array( 'uid' => '9', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '黄建', 'level' => '普通会员', 'trade_account' => '154548', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '1', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), 5 => array( 'uid' => '10', 'username' => '', 'password' => '', 'user_status' => '1', 'login_number' => null, 'last_login_time' => null, 'last_login_ip' => null, 'nickname' => '', 'mobile' => '18879701814', 'realname' => '张科', 'level' => '普通会员', 'trade_account' => '9527', 'reg_time' => null, 'recom_account' => '568050269', 'total' => null, 'is_apply' => '0', 'is_checked' => '0', 'haschild' => '0', 'count' => 0, 'total_count' => 0, 'childlist' => null, ), ); </code>
Ich habe zum Debuggen auf http://www.thinkphp.cn/topic/... verwiesen, konnte aber den Rückgabewert nicht erhalten.