0

I tried to have this multi-dimensional array on Quotes>Sections>Departments I have a problem with getting the first iteration of the foreach-ed

$Department->getActuals();

$actuals = array();

foreach($quotes as $quoteID => $Quotes) {
                $invoiceTotal = $Quotes->getInvoicedValue();
                if($invoiceTotal['Total'] > 0) {
                    $labourCost = 0;
                    $actualHours = 0;
                    $sections = $Quotes->getSections();
                    foreach ($sections as $Sections) {
                        $departments = $Sections->getDepartments();
                        foreach($departments as $Department) {
                            $actuals = $Department->getActuals(null, null, false);
                            Console::Log('actuals', $actuals);
                        }
                    }
                }
            }

Console::Log('actuals', $actuals);

How to get the first element result in Php using foreach?

Thank you in advance

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Two
  • 512
  • 4
  • 17
  • What is the problem? – gview Oct 27 '17 at 00:22
  • @gview Sorry for the late reply. I can't get the first iteration of foreached $Department. $actual variable when consoled gives multiple results. `code` Console::Log('actuals', $actuals); `code` `code` $actuals = $Department->getActuals(null, null, false); `code` Thanks in advance – Two Oct 27 '17 at 00:24
  • I have no idea what you mean. Is $actuals an array? – gview Oct 27 '17 at 00:28

2 Answers2

1

If $actuals is an array, you can access the first element via array notation. Arrays in php are 0 based.

Console::Log('actuals', $actuals[0]);

Based on your statement that $actuals is an array with a number of associative keys within, you can get a human readable form using print_r, and passing the true parameter to return the output rather than printing it.

Console::Log('actuals', print_r($actuals, true));
gview
  • 14,876
  • 3
  • 46
  • 51
  • My apology for super late reply. This problem was year ago, and I think was resolved. Thanks gview for the help. – Two Nov 26 '19 at 15:51
0

The correct solution was answered by gview

Console::Log('actuals', $actuals[0]);
Two
  • 512
  • 4
  • 17