It sounds like you want to grab the first element from an array without having to scroll through the rest of them.
PHP provides a set of functions for such situations.
To get the first element in an array, start with the reset() function to position the array pointer at the beginning of the array, then use the current() function to read the element that the pointer is looking at.
So your code will look like this:
<?php reset($report['edits']); $report_edit = current($report['edits']); ?>
Now you can work with $report_edits without using the foreach() .
(note that the array pointer actually starts by default in the first entry, so you can skip the reset() call, but itβs best not to do this because it can be changed elsewhere in your code if you are not aware of it)
If after that you want to go to the next record, you can use the next() function. As you can see, if you wanted, it would theoretically be possible to use these functions to write an alternative type of foreach() . There would be no point in using them in this way, but it is possible. But they allow more small-scale control over the array, which is convenient for situations like yours.
Hope this helps.
source share