Jump to content
MakeWebGames

This arrray work?


AlabamaHit

Recommended Posts

I don't want to say exactly what this is for...but here it is.....its a project im working on was wondering if this would work.....

 

$time = rand(1,5);

$random = array('1' , '2' , '3' , '4' , '5');

$newtime = array('5' , '10' , '15', '20, '25');

$newtimes = str_replace($random, $newtime);

$query = sprintf('UPDATE `users` SET `something` = ("%u")' , $newtime);

        mysql_query($query) or die (mysql_error());

 

What I am trying to do is make it udate the users "something" to a random number but only in the array like in example the array 5, 10, 15, 20, 25...

To try to explain better....I want it to run a random nubmer 1,2,3,4,5 <<< those random numbers.

Then i want it to replace those numbers (1,2,3,4,5,) with these numbers 5,10,15,20,25...

Then I want it to update the users "something" with the replaced number.....^^^^^^^

EDIT:

Or maybe this one?

$time = rand(1,5);

$newtime = str_replace(array('1' , '2' , '3' , '4' , '5'), array('5', '10', '15, '20', '25');

$query = sprintf('UPDATE `users` SET `something` = ("%u")' , $newtime);

        mysql_query($query) or die (mysql_error());

 

What I am trying to get to is a random number of only increment of 5 (between 5-25)

Link to comment
Share on other sites

Guest Anonymous

Re: This arrray work?

Not 100% sure what you mean but ...

 

$array = array
(
0 => 5,
1 => 10,
2 => 20,
3 => 40,
4 => 80,
);

$rand  = mt_rand(0, 4);
$value = $array[$rand];

 

Now, $value contains one of the value (5, 10, 20, 40 or 80)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...