Re: What is meant by this code?
| From: | Aziz Saleh | Date: | Sun, 01 Feb 2015 00:44:23 +0000 |
| Subject: | Re: What is meant by this code? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324354@lists.php.net to get a copy of this message | ||
On Sat, Jan 31, 2015 at 7:39 PM, Abdul Abdul <abdul.sw84@gmail.com> wrote:
> Lester.
>
> Thanks for your reply. What is confusing me most is:
>
> $exif as $key => $section
>
> I understood the foreach from the manual, and we have to have a key/value.
> But, what is =>?
>
> On Sat, Jan 31, 2015 at 12:28 AM, Lester Caine <lester@lsces.co.uk> wrote:
>
> > On 31/01/15 02:06, Ken Robinson wrote:
> > >> Hello,
> > >>
> > >> I'm new to PHP. I came across the following code:
> > >>
> > >> ....
> > >> ....
> > >> $exif = exif_read_data($image);
> > >> foreach ($exif as $key => $section) {
> > >> foreach ($section as $name => $val) {
> > >> .....
> > >> .....
> > >>
> > >> What are we doing here in the "foreach"? What is "as"?
> > >
> > > RTFM
> > >
> > >
> > > http://php.net/manual/en/control-structures.foreach.php
> >
> > I've read the manual ... now I'm more confused :)
> > Seriously ... If one is starting to use PHP reading the manual is the
> > LAST place to start, but there is not a good alternative to direct
> > people to. Most tutorials are simply last in old style practices!
> >
> > Abdul ...
> > A useful little trick is print_r($exif);
> > This will show just what has been returned by exif_read ... which is an
> > multi level array of data. foreach simply scans the array converting
> > each element of the array - in this case creating a copy of an element
> > in $section, but $section is an array itself so the second foreach pulls
> > out the values.
> >
> > Now hopefully reading the manual will make a little more sense :)
> >
> > --
> > Lester Caine - G8HFL
> > -----------------------------
> > Contact - http://lsces.co.uk/wiki/?page=contact
> > L.S.Caine Electronic Services - http://lsces.co.uk
> > EnquirySolve - http://enquirysolve.com/
> > Model Engineers Digital Workshop - http://medw.co.uk
> > Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
Please don't top post, putting your replies on top, should be on bottom of
convo (it is against the rules).
A good explanation w/example can be found here:
http://stackoverflow.com/a/1241831/1935500
In a nutshell it is a separator between the key and value in arrays/objects
used in foreach loops.