I am facing a problem, few days ago I had this issue which is solved but when I was retrieving data it was object so with the help of the below code I have converted that as array but now when I try to access the array I am getting Undefined index notice.
Controller
public function downline_income($userId = null, $offset = 0) {
$userId = user::id();
$limit = AZ::setting('record_per_page');
$objUser = new User_Object;
$objUser->id = $userId;
$downline = $this->user->getDownline($objUser);
$downline = $this->object_to_array($downline);
AZ::layout('left-content', array(
'block' => 'account/downline_income',
'user' => $userId,
'q' => $userId,
'data' => $downline,
));
public function object_to_array($obj) {
if (is_object($obj))
$obj = (array) $obj;
if (is_array($obj)) {
$new = array();
foreach ($obj as $key => $val) {
$new[$key] = $this->object_to_array($val);
}
} else
$new = $obj;
return $new;
}
When var_dump in downline_income.php(view) below is the output.
//code
$as = $data;
echo "<pre>";
print_r($as['User_Objectchildren']);
OUTPUT
array(3) {
["User_Objectchildren"]=>
array(10) {
[0]=>
array(22) {
["User_Objectchildren"]=>
array(0) {
}
["level"]=>
int(1)
["id"]=>
string(4) "1147"
["gid"]=>
string(1) "4"
//
...
And on print_r
Array
(
[User_Objectchildren] => Array
(
[0] => Array
(
[User_Objectchildren] => Array
(
)
[level] => 1
[id] => 1147
[gid] => 4
[parent_id] => 1112
[username] => test 9
[email] => [email protected]
[name] => test9
[status] => 0
[registerd] => 2017-04-20 09:03:10
[last_login] => 0000-00-00 00:00:00
[password] => 4eca045dfa240f56a1f9d45eaa53b71c6eccd6a7
[tranjection_password] =>
[package_id] => 6
[user_id] => 1147
[purchase_date] => 2017-04-20 09:03:11
[confirm_date] => 0000-00-00 00:00:00
[package_name] => USD 1000
[amount] => 1000
[daily_income] => 12
[total_income] => 600
[time_duration] => 60
)
[1] => Array
(
[User_Objectchildren] => Array
(
)
[level] => 1
[id] => 1146
[gid] => 4
[parent_id] => 1112
[username] => test8
.....
When try to print print_r($as['User_Objectchildren']);
A PHP Error was encountered
Severity: Notice
Message: Undefined index: User_Objectchildren
Filename: account/downline_income.php
Line Number: 43
print_r($as['User_Objectchildren']);is the code on #43$as? In your question there is no connection between the line with the error and the code block you provided... If you could show one code block which both defines the variable and produces the error, we could say something more useful.