Hi all,
I need a weight system (or pointers/ideas for it) in PHP.
Currently i have a working piece of code and want to expand it with a weight system.
This code creates an array based on some conditions and variables.
array(0 => 2, 1 => 5, 2 => 10)
This array is flexible and can vary in length. Anything from 1 to many items.
The 2 5 and 10 are ID's of database records and can be different at any moment.
I've considered putting the weighting in the query but decided against it, otherwise i have to rewrite the rest of the system, which i don't fancy at this point. (unless it's the best most awesome way ofcourse)
I've found some examples, also on this forum, which create an array where items are listed multiple times in their array to increase their chance of being shown. This is no good because of a array_rand() later on which in some cases kicks in. I don't want the same item picked multiple times.
My idea is to create a 2nd array parallel to this one with weight numbers corresponding to those ideas and in some magical phpey way apply that to the existing method (above array) to sort that array by weight. That still leaves the randomizer as an uncertain factor but once i get some ideas/headstart i can figure that out i hope!
I have no code for the weight yet as i can't think of a way to do it 🙁
Any ideas, thoughts, comments welcome!!
Thanks!