Hi guys, its nice meeting you all, forgive me i might be asking simple questions believe me im totaly new to PHP and im so lost. Help me out with this.

Create an array with random number of elements and each value and each value is random itself. Display array content.

This is what i have tried:

<?php
$numbers = 10;

$data = range(1, 10);
$random = array_rand($data,$numbers);

for($i=0; $i<$numbers; $i++)
{
	print $random[$i];
}

?>

it works but how do i create an array to answer this:
thank u in advance!!!!!!!!!!!!!
please drop me an email at [snipped]

Recommended Answers

All 2 Replies

Try

$ArrayLength = rand(0,100);//The array will be between 0 and 100 entries
$i = 0;//Incremental
$RandArray = array();
while ( $i <= $ArrayLength ) {//Until the array length is reached
     $RandArray[$i] = rand(1,100);//Set a value between 1 and 100
     $i++;//Add to the increment
}
echo "<pre>";//Create an output for plain text
print_r($RandArray);//Print out the array with formatting
echo "</pre>";//Close output

Is that what you needed?

That is axactly what i was looking for samarudge, thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.