treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] get key value of looped element

  • I am looping like this

    foreach ($images as $image)

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

  • Easy.

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

    Happy coding =)

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

  • 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!

  • 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.

  • 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.

  • 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.

  • 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.

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

  • 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.