Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. [urgent] [php] arrays [modified]

[urgent] [php] arrays [modified]

Scheduled Pinned Locked Moved Web Development
phpdata-structuresquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam 2006
    wrote on last edited by
    #1

    hi all, i'm using php and i have a large array (it has several thousand entries). i need to search the array, several thousand times, for a value. the in_array() function works, but the page takes a while to be generated. is their a faster function or way to find out if an element exists in an array? thanks in advance. -- modified at 0:52 Monday 21st August, 2006

    G 1 Reply Last reply
    0
    • S Sam 2006

      hi all, i'm using php and i have a large array (it has several thousand entries). i need to search the array, several thousand times, for a value. the in_array() function works, but the page takes a while to be generated. is their a faster function or way to find out if an element exists in an array? thanks in advance. -- modified at 0:52 Monday 21st August, 2006

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Make sure that the values are sorted in the array, so that you can use a binary search[^]. That would significantly speed up the process. Looping to find a value in an array of 10000 values would need an average of 5000 compares, while binary search will use around 14 compares. That would mean that the process would be around 350 times faster.

      --- b { font-weight: normal; }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups