ryeman98 Posted February 5, 2008 Share Posted February 5, 2008 So I've got this one script. I need to know, how can I make an array work when I'm unsure of the size and values of it? If you don't understand, I'll try to go more in-depth but it's tough. Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/ Share on other sites More sharing options...
Aureole Posted February 5, 2008 Share Posted February 5, 2008 I use arrays a lot without knowing how big they are etc... you need to explain in more detail... Though you do realize there are functions that can count how big an array is etc. Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458381 Share on other sites More sharing options...
ryeman98 Posted February 5, 2008 Author Share Posted February 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458387 Share on other sites More sharing options...
ryeman98 Posted February 5, 2008 Author Share Posted February 5, 2008 Bumping because I'm a little short for time Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458403 Share on other sites More sharing options...
Aureole Posted February 5, 2008 Share Posted February 5, 2008 I really don't get what you're asking, sorry... hopefully someone else will. Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458405 Share on other sites More sharing options...
ryeman98 Posted February 5, 2008 Author Share Posted February 5, 2008 Ok, this is what my array looks like: $numbers = array(); And it's like that because I don't know how much info is going to be inserted. Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458409 Share on other sites More sharing options...
ryeman98 Posted February 5, 2008 Author Share Posted February 5, 2008 Maybe this helps because this is what I want: $numbers = array(Lowest, Highest); And that sets the array's dimension ... does that help? Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458421 Share on other sites More sharing options...
poe Posted February 5, 2008 Share Posted February 5, 2008 if your probability number is... lets say 17, then howabout: for ( $min= 1; $max<= 17; $counter ++) { $myarray[] = $counter; } for output: print_r($myarray); Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458425 Share on other sites More sharing options...
ryeman98 Posted February 5, 2008 Author Share Posted February 5, 2008 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458431 Share on other sites More sharing options...
ryeman98 Posted February 5, 2008 Author Share Posted February 5, 2008 Curse questioning your own programming! Quote Link to comment https://forums.phpfreaks.com/topic/89492-solved-how-do-i-make-an-array-when/#findComment-458439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.