Jump to content

[SOLVED] How do I make an array when ...


ryeman98

Recommended Posts

I'll try as best as I can.

 

I have an array but I don't know how big it'll be.

I count the number of columns in the database and then select a random number. rand(1, $row['COUNT(id)']);

Then from that, it selects the column of the random number.

 

There is a column called probability. It calculates the chances of the thing being true out of 100. Then, whatever the probability number is, that is the size the array is going to be and another variable adds a random number to each array.

 

Then, there is some other stuff but it isn't relevant.

if your probability number is... lets say 17, then

 

howabout:

 

for ( $min= 1; $max<= 17; $counter ++) {

 

$myarray[] = $counter;

 

}

 

for output:

 

print_r($myarray);

 

Well ... that helps out a little but I got that far. I guess I'm just looking for some kind of function to set the dimension of an array. Well hang on, this is how it works:

 

Say 5 was the prob number:

within your for loop

 

$numbers[$counter]; // Same as: $numbers['1'];

$numbers[$counter]; // Same as: $numbers['2'];

 

and so on ...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.