I am trying to insert 3 objects of different classes into an array, such that, the array looks like this [objA,.., objA, objB,.., objB, objC,..., objC].
The way I have my function set up is to get a rand for number of times each of objA, objB and objC will be inserted into the array, then have 3 for loops to insert each of the objects.
$no_of_objA = rand(5, 10);
$no_of_objB = rand(1, 5);
$no_of_objC = rand(3, 8);
for($i = 0; $i < $no_of_objA; $i++)
$this->users[$i] = new A();
for($i = $no_of_objA; $i < ($no_of_objA + $no_of_objB); $i++)
$this->users[$i] = new B();
for($i = ($no_of_objA + $no_of_objB); $i < ($no_of_objA + $no_of_objB + $no_of_objC); $i++)
$this->users[$i] = new C();
The worst case for this obviously will be Big-O of largest number generated form the rand function. This works fine, but, I'm kind of thinking there may be a more elegant and optimized solution to achieving this.
I'm not really concerned by the order the objects are inserted...