Unnatural sort of PHP array -


I have an array in PHP which is just strings. These string relationships represent relationships that can occur between different distances of the family. It looks like:

  0 = & gt; 'Unknown', 1 = & gt; 'Parent', 2 = & gt; 'Grandfather', 3 = & gt; 'Sibling', 4 = & gt; 'Hair', 5 = & gt; 'Dai', 6 = & gt; 'Husband', 7 = & gt; 'Self', 9 = & gt; 'Phase Generator', 10 = & gt; 'Step sibling', 11 = & gt; 'Step child', etc. ...   

This array works great, but I am running into a problem where I can be able to sort these items in a pure way I want to (especially close to far-away father / brother, starting from far-away farthest farther-far-far-far-far-far-far-far-far-distant-places As well as X-Law-Law), but I would also like to add the list over time. My initial thought was that they were ordered to order them, because they needed to be ordered in the array, but they did not allow me to add links in the later date (although it is doubtful that it will ever happen, I will Should be safe even from sorry). The best solution I could come up with (a good one that appears in my mind) was to create a simple PHP object that would maintain the relationship name and such a arbitrary "sort" value like New Relation ('Unknown', 0); The problem is, it seems that you can not instantize objects while X => Y syntax, as I have syntax errors when I try to write it:

  0 = & gt; New Relationship ('Unknown', 0), 1 = & gt; New relationship ('grandfather', 1), etc ...   

Is there a way that this can work or possibly a better solution? It seems that at this point I might have to create an array when first request is made using Array (stored in ester), but I want to format it well. Am i out of luck

Edit - To clarify: Now the key is being used as a stored value in the database In short, we are using the array as an anem in other languages.

Use the array as a map, such as relationship_name = & gt; Relationship_distance. If it is more convenient, then you can see the relationship_distance = & gt; can do. Relationship_name Make relationships / interchange values ​​arbitrarily, with intervals in between, so that the intermediate distance can be added later. For example:

  'sibling' = & gt; 1, 'Parent' = & gt; 10, 'grandfather' = & gt; 20, 'Great BrandPaint' = & gt; 30, 'uncle' = & gt; 13, 'Brother inline' = & gt; 17,   

You can then sort the map with their keys or values ​​and add new entries as needed.

Comments