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

3
  • What is the problem? Commented Oct 27, 2017 at 0: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 Commented Oct 27, 2017 at 0:24
  • I have no idea what you mean. Is $actuals an array? Commented Oct 27, 2017 at 0:28

2 Answers 2

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));
Sign up to request clarification or add additional context in comments.

1 Comment

My apology for super late reply. This problem was year ago, and I think was resolved. Thanks gview for the help.
0

The correct solution was answered by gview

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.