1

I have array of array and I did a print_r of it and it returned this...

Array ( 
    [0] => Array 
    ( 
        [0] => Array 
        ( 
            [cust_id] => xl 
            [project_id] => central 
            [tot_ticket] => 1 
            [person] => [email protected] ) 
        [1] => Array 
        ( 
            [cust_id] => tsel 
            [project_id] => jabo1 
            [tot_ticket] => 1 
            [person] => [email protected] ) 
        [2] => Array 
        ( 
            [cust_id] => isat 
            [project_id] => jabo2 
            [tot_ticket] => 1 
            [person] => [email protected] ) ) )

I write this in my controller right now:

for ($i=0; $i<count($customerField); $i++) {
                for ($j=0; $j<count($activityField); $j++) { 
                    for ($k=0; $k<count($userIdField); $k++) { 
                        array_push($data, $this->queries_trend->fetch_ajax($customerField[$i], $activityField[$j], $userIdField[$k]));
                            foreach ($data as $value) {
                                $test .= '
                                            <tr>
                                                <td>' . $value[$i][$j]['cust_id']->cust_id . '</td>
                                                <td>' . $value[$i][$j]['project_id'] ->project_id. '</td>
                                                <td>' . $value[$i][$j]['tot_ticket']->tot_ticket . '</td>
                                                <td>' . $value[$i][$j]['person']->person . '</td>
                                            </tr>';    
                            }
                    }

                }
            }

I have problem to get the value of each array, anyone here can help me to find the solution?

3
  • 1
    you just need a two foreach loop Commented Nov 17, 2018 at 9:02
  • okay, i'll try sir Commented Nov 17, 2018 at 9:04
  • i've make for two foreach loop, the errors are "Trying to get property of non-object" Commented Nov 17, 2018 at 9:09

1 Answer 1

1

You are trying to access the data from an object using ['cust_id']->cust_id, but you have an array, so you could use just ['cust_id'] instead.

Try using for example a foreach:

$test = "";
foreach ($arrays as $data) {
    foreach ($data as $value) {
        $test .= "<tr>";
        $test .= "<td>" . $value["cust_id"] . "</td>";
        $test .= "<td>" . $value["project_id"] . "</td>";
        $test .= "<td>" . $value["tot_ticket"] . "</td>";
        $test .= "<td>" . $value["person"] . "</td>";
        $test .= "</tr>";
    }
}

echo $test;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.