get key value of looped element

  • # March 4, 2013 at 8:24 am

    I am looping like this

    foreach ($images as $image)

    how can i get the key value of $image in $images?

    # March 4, 2013 at 9:04 am

    This reply has been reported for inappropriate content.

    Easy.

    foreach ($images as $key => $image) {
    //Do something with the $key and image
    }

    Happy coding =)

    # March 4, 2013 at 9:51 am

    thank you, i’m still a noob in php your help is really appreciated

    # March 4, 2013 at 9:54 am

    This reply has been reported for inappropriate content.

    No worries. I’d recommend looking over the PHP Manual, and also making sure that you’re showing all errors (in development not in production).

    Good luck!

    # March 4, 2013 at 9:59 am

    > in development not in production

    ain’t nobody got time for that. Really I think it’s not that big deal unless you’r coding for hospitals and stuff like that.

    # March 4, 2013 at 10:00 am

    >ain’t nobody got time for that. Really I think it’s not that big deal unless you’r coding for hospitals and stuff like that.

    So professionalism and error checking is a waste of time?

    Sigh.

    # March 5, 2013 at 2:59 am

    This reply has been reported for inappropriate content.

    O.o Why… would you ever think it’s a good idea to release something half-assed? Every error (even if it’s one that just shows the idiosyncrasies of PHP) teaches you and lets you get better.

    # March 5, 2013 at 3:32 am

    Answer is simple. My current job is not worth it, my manager is completely retarded. So unless users don’t have any issues or it’s my own project I won’t bother double checking stuff.

    # March 5, 2013 at 5:10 am

    This reply has been reported for inappropriate content.

    Wow. You have my sympathies and hope that your search for a better job is going well.

    # March 5, 2013 at 5:36 am

    Nah, I won’t search any other job. By the end of the March I’ll run my own company, everything is ready, need to find better place for office and move everything there. I really appreciate your wishes tho, thank you.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed