Search code examples
phparrayssortingstructassociative

What PHP data structure suits the storage of web urls and descriptions etc?


I want to store the following pieces of information in a structure or array of some sort in PHP;

  • URL
  • Title
  • Description
  • Rank

I want the data to be associative, that a particular URL refers to a Title, Description & Rank.

I want to be able to sort the data then by rank, then echo it in that order, with each element still being associated.

Should I use associative arrays? Structs? Or some other PHP data structure?

Thanks


Solution

  • $urls["http://example.com"] = array(
        "rank" => 3,
        "title" => "abc",
        ...
    )
    

    and use uasort for ordering