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
https://forums.phpfreaks.com/topic/131671-need-help-wont-output/
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

Archived

This topic is now archived and is closed to further replies.

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