Jump to content

Need Help- Wont output


doucettej3

Recommended Posts

This code takes an array of random size nd with random integers and then finds the smallest value in the array. Im pretty sure the rest of the code is right up to the output. Any help would be awesome. heres the code

function smallest($passed_array)
{
//initialize the $smallest variable
$smallest = $random_max;
for($i = 0; $i <= $random_quantity; $i++)
{	if($smallest > $passed_array[$i])
{
$smallest = $passed_array[$i];
}
else
{
$smallest = $smallest;
}	
} 
print_r($random_numbers);
echo "<br>The Smallest number is $small";
}

Link to comment
Share on other sites

You don't need a function to get the smallest number in an array, just use rsort() and the smallest number is the $array[0]

 

Example:

<?php
$rand_array = range(1,100);
shuffle($rand_array);
echo 'Suffled Array: ' . implode(', ',$rand_array) . '<br>';	
$rand_array = array_slice($rand_array,rand(0,30),rand(50,100));
echo 'Sliced Array: ' . implode(', ',$rand_array) . '<br>';	
sort($rand_array);
echo 'Array contents: ' . implode(', ',$rand_array) . '<br>';
echo 'The smallest number is: ' . $rand_array[0];
?>

 

Ken

Link to comment
Share on other sites

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.