On Thu, Jun 27, 2013 at 6:14 PM, Johannes Schlüter
<johan...@schlueters.de>wrote:

> On Thu, 2013-06-27 at 16:58 +0200, Nikita Popov wrote:
> > On Thu, Jun 27, 2013 at 4:10 PM, Christian Stoller <stol...@leonex.de
> >wrote:
> >
> > > The new syntax could make it shorter and faster to write... but maybe
> it's
> > > a bit too confusing?
> > >
> > > $count = 0;
> > > foreach ($array as $key => $innerArray as $innerKey => $value) {
> > >     $count += $value;
> > >     // and do something with $key and $innerKey
> > > }
> > >
>

With the addition of array_column in php 5.5, this can be done in a much
cleaner way:

$array = array(
    array('value' => 1),
    array('value' => 2),
    array('value' => 3),
);

$count = 0;

foreach(array_column($array, 'value') as $value) {
 $count += $value;
}

Reply via email to