Web Analytics Made Easy -
StatCounter return keys - CodingForum

Announcement

Collapse
No announcement yet.

return keys

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • return keys

    I have an associative array but i wnat to do a reverse lookup. So if I have a value that is within one of the elements of my array and i wish to return the key that of that element. How can i do this.

    PHP Code:
    // $value is the variable to lookup

    foreach ($Arr as $element)
    {
     if (
    $element==value) return $key

    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    You can use the foreach ($Arr as $key => $element) syntax, then return $key when your condition is true.

    Comment


    • #3
      That will work

      Anyone know why when i use the condition it is always returning false because a char from one side is returning chr(38) and the other chr(233). Why is the encoding different?

      I need to know why because I will get this problem with every string compare through out the site.
      Last edited by timgolding; Sep 29, 2006, 12:18 PM.
      You can not say you know how to do something, until you can teach it to someone else.

      Comment


      • #4
        Can we see some examples? I don't follow what you're saying.

        Comment


        • #5
          array_search()
          I'm not sure if this was any help, but I hope it didn't make you stupider.

          Experience is something you get just after you really need it.
          PHP Installation Guide Feedback welcome.

          Comment

          Working...
          X