1
어떻게 다차원 배열 재귀 PHP를 평평하게하는. 이 코드로 시도했지만 작동하지 않습니다. 나는 또한 다른 많은 링크를 시도했지만 작동하지 않습니다. This이 배열을 만드는 데 코드가 사용되었습니다.평면 다차원 배열 재귀 PHP
public function downline_income($userId = null, $offset = 0) {
$userId = user::id();
$limit = AZ::setting('record_per_page');
$objUser = new stdClass();
$objUser->id = $userId;
$downline = $this->user->getDownline($objUser);
AZ::layout('left-content', array(
'block' => 'account/downline_income',
'user' => $userId,
'total_users' => $total_users,
'pagination' => $pagination,
'q' => $userId,
'data' => $downline,
'offset' => $offset,
));
}
public function getDownline($obj, $level = 0) {
$obj->level = $level;
$where = array('parent_id' => $obj->id);
$this->db->select('users.*');
$this->db->where($where);
$query = $this->db->get('users')->result();
foreach ($query as $objUser) {
$obj->data[] = $this->getDownline($objUser, ($level + 1));
}
return $obj;
}
다음은 평평하게 배열해야하는 배열입니다.
Array
(
[0] => stdClass Object
(
[id] => 1135
[gid] => 4
[parent_id] => 1112
[username] => sdafasdf
[email] => [email protected]
[name] => sdafsda
[status] => 0
[registerd] => 2017-04-19 15:44:38
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 5
[user_id] => 1135
[purchase_date] => 2017-04-19 15:44:39
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 500
[amount] => 500
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 1
)
[1] => stdClass Object
(
[id] => 1134
[gid] => 4
[parent_id] => 1112
[username] => sdaf254
[email] => [email protected]
[name] => categoryA
[status] => 0
[registerd] => 2017-04-19 15:36:11
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 4
[user_id] => 1134
[purchase_date] => 2017-04-20 00:00:00
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 250
[amount] => 250
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 1
)
[2] => stdClass Object
(
[id] => 1136
[gid] => 4
[parent_id] => 1112
[username] => test
[email] => [email protected]
[name] => test
[status] => 0
[registerd] => 2017-04-20 08:49:25
[last_login] => 2017-04-21 10:42:25
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 7
[user_id] => 1136
[purchase_date] => 2017-04-20 08:49:25
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 2500
[amount] => 2500
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 1
[data] => Array
(
[0] => stdClass Object
(
[id] => 1148
[gid] => 4
[parent_id] => 1136
[username] => test_downline
[email] => [email protected]
[name] => test_downline
[status] => 0
[registerd] => 2017-04-21 10:42:56
[last_login] => 2017-04-21 11:08:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 9
[user_id] => 1148
[purchase_date] => 2017-04-21 10:42:56
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 10000
[amount] => 10000
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 2
[data] => Array
(
[0] => stdClass Object
(
[id] => 1150
[gid] => 4
[parent_id] => 1148
[username] => test1_downline1
[email] => [email protected]
[name] => test1_downline1
[status] => 0
[registerd] => 2017-04-21 11:08:27
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 5
[user_id] => 1150
[purchase_date] => 2017-04-21 11:08:27
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 500
[amount] => 500
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 3
)
)
)
[1] => stdClass Object
(
[id] => 1149
[gid] => 4
[parent_id] => 1136
[username] => test_downline2
[email] => [email protected]
[name] => test_downline2
[status] => 0
[registerd] => 2017-04-21 11:06:35
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 6
[user_id] => 1149
[purchase_date] => 2017-04-21 11:06:35
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 1000
[amount] => 1000
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 2
)
)
)
[3] => stdClass Object
(
[id] => 1137
[gid] => 4
[parent_id] => 1112
[username] => test2
[email] => [email protected]
[name] => test 2
[status] => 0
[registerd] => 2017-04-20 08:54:59
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 6
[user_id] => 1137
[purchase_date] => 2017-04-20 08:55:00
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 1000
[amount] => 1000
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 1
)
나는 아래의 코드를 시도했지만 그것은 단지 수준
Array
(
[0] => stdClass Object
(
[id] => 1135
[gid] => 4
[parent_id] => 1112
[username] => sdafasdf
[email] => [email protected]
[name] => sdafsda
[status] => 0
[registerd] => 2017-04-19 15:44:38
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 5
[user_id] => 1135
[purchase_date] => 2017-04-19 15:44:39
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 500
[amount] => 500
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 1
)
[1] => stdClass Object
(
[id] => 1134
[gid] => 4
[parent_id] => 1112
[username] => sdaf254
[email] => [email protected]
[name] => categoryA
[status] => 0
[registerd] => 2017-04-19 15:36:11
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 4
[user_id] => 1134
[purchase_date] => 2017-04-20 00:00:00
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 250
[amount] => 250
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 1
)
[2] => stdClass Object
(
[id] => 1136
[gid] => 4
[parent_id] => 1112
[username] => test
[email] => [email protected]
[name] => test
[status] => 0
[registerd] => 2017-04-20 08:49:25
[last_login] => 2017-04-21 10:42:25
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 7
[user_id] => 1136
[purchase_date] => 2017-04-20 08:49:25
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 2500
[amount] => 2500
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 1
)
[3] => stdClass Object
(
[id] => 1148
[gid] => 4
[parent_id] => 1136
[username] => test_downline
[email] => [email protected]
[name] => test_downline
[status] => 0
[registerd] => 2017-04-21 10:42:56
[last_login] => 2017-04-21 11:08:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 9
[user_id] => 1148
[purchase_date] => 2017-04-21 10:42:56
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 10000
[amount] => 10000
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 2
)
[4] => stdClass Object
(
[id] => 1150
[gid] => 4
[parent_id] => 1148
[username] => test1_downline1
[email] => [email protected]
[name] => test1_downline1
[status] => 0
[registerd] => 2017-04-21 11:08:27
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 5
[user_id] => 1150
[purchase_date] => 2017-04-21 11:08:27
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 500
[amount] => 500
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 3
)
[5] => stdClass Object
(
[id] => 1149
[gid] => 4
[parent_id] => 1136
[username] => test_downline2
[email] => [email protected]
[name] => test_downline2
[status] => 0
[registerd] => 2017-04-21 11:06:35
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 6
[user_id] => 1149
[purchase_date] => 2017-04-21 11:06:35
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 1000
[amount] => 1000
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
[level] => 2
)
당신이 무엇을 필요로하는 경우 알려줘 2
public function array_flatten($array, $i = 0) {
$flat = array();
foreach ($array as $value) {
if (isset($value->data) && is_array($value->data)) {
$flat = array_merge($flat, $this->array_flatten($value->data));
} else {
$flat[] = $value;
}
}
return $flat;
}
욕망 출력을위한 작업입니다.
예상되는 결과는 무엇입니까? – hassan
@hassan 업데이트 된 질문 확인 –