Jump to content

Recommended Posts

Hello everyone,

 

I have been trying several things,recently, and I can't figure out how to get a series of numbers, grouped together as a string of number, instead of it adding or grabbing the last number that was randomly generated.

 

I'm wanting to save it in a variable (of course), so I can pass it though a query when it is needed.

 

foreach($array as $number){
echo $number;
}

 

$array is the variable where it is an array but all the randomly generated numbers are stored there.

 

All / any help would be gratefully appreciated.

Link to comment
https://forums.phpfreaks.com/topic/249993-an-easy-way-to-extract-array-data/
Share on other sites

Ok, my random number go between 1-20, and it loops 5 times. So my array would look like

$array = array();
for($i = 0; $i<5; $i++){
$array[$i] = rand(0,20);
}

So my array has the all the random numbers in there.

 

But what I'm trying to do as my goal: is to put all the numbers as a STRING. So it looks like: 1510253, instead of it being added together, and put them in a variable so that was I don't have to do a foreach statement in my query (which is bad in my opinion).

 

 

The implode Function does work. I've never used it until now... Thank you very much Maniac!

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.