Ok i am trying to create a simple program that will allow me to use an array with 8 numbers, the output form should show the numbers in their original order that the user inputs them, in numerical order, Highest number, lowest number and then the average number. If anyone could help me it would be much appreciated. here's waht i have so far.

<?php
if (isset($_POST['numbers']))
//if (is_numeric($_POST['numbers']))
//if (!empty($_POST['numbers'])) 
{ 
    $Numbers = $_POST['numbers'];
	$big = max($Numbers);  
	$small = min($Numbers);
	$average = array_sum($Numbers) / count($Numbers);
	print "Original Sequence:<br>";

	$sorted = sort($Numbers);	
 	print "Sorted Numbers: $sorted";
	echo implode(" ",$Numbers);
	print "<br>Largest Number: $big<br>";
	print "Smallest Number: $small<br>";
	print "Average Number: $average<br>";}
else {
	print "<font color='red'>Invalid Input Grades must be Numeric</font>";}
		
	 
	?>

Recommended Answers

All 13 Replies

Ok i am trying to create a simple program that will allow me to use an array with 8 numbers, the output form should show the numbers in their original order that the user inputs them, in numerical order, Highest number, lowest number and then the average number. If anyone could help me it would be much appreciated. here's waht i have so far.

<?php
if (isset($_POST['numbers']))
//if (is_numeric($_POST['numbers']))
//if (!empty($_POST['numbers'])) 
{ 
    $Numbers = $_POST['numbers'];
	$big = max($Numbers);  
	$small = min($Numbers);
	$average = array_sum($Numbers) / count($Numbers);
	print "Original Sequence:<br>";

	$sorted = sort($Numbers);	
 	print "Sorted Numbers: $sorted";
	echo implode(" ",$Numbers);
	print "<br>Largest Number: $big<br>";
	print "Smallest Number: $small<br>";
	print "Average Number: $average<br>";}
else {
	print "<font color='red'>Invalid Input Grades must be Numeric</font>";}
		
	 
	?>
$var = array(1,2,3,4,5);
foreach($var as $number){
    echo $number;
}

I need help with displaying the original order of the numbers selected, and when i try to do "is_numeric" my output goes blank or it only displays the error message i created.

I need help with displaying the original order of the numbers selected, and when i try to do "is_numeric" my output goes blank or it only displays the error message i created.

did you even see the example above?

The original numbers come form the text boxes on the form which is an array, trying to figure out why it won't display the Values entered by the user. my output for the "Original Sequence" returns the word "Array" instead of the numbers in original order. the example above doesnt help me

Here is what i have now:

<?php

if (isset($_POST['numbers']))

{ 
    $Numbers = $_POST['numbers'];
	$big = max($Numbers);  
	$small = min($Numbers);
	$average = array_sum($Numbers) / count($Numbers);
	$original = ("$Numbers");
	print "<font color='LightSlateGrey'>Original Sequence: $original</font><br>";

	$sorted = sort($Numbers);	
 	print "Sorted Numbers: $sorted";
	echo implode(" ",$Numbers);
	print "<br><font color='green'>Largest Number: $big</font><br>";
	print "<font color='purple'>Smallest Number: $small</font><br>";
	print "<font color='aqua'>Average Number: $average<br></font><br>";}
else {
	print "<font color='red'>All Entries Must be Numeric</font>";}
		
	 
	?>

Comment everything else and put this code and post back the output

if (isset($_POST['numbers'])){
    print_r($_POST);

}

Here's the output

Array ( [numbers] => Array ( [0] => 1 [1] => 4 [2] => 6 [3] => 7 [4] => 8 [5] => 9 [6] => 99 [7] => 21 ) )

Here's the output

Array ( [numbers] => Array ( [0] => 1 [1] => 4 [2] => 6 [3] => 7 [4] => 8 [5] => 9 [6] => 99 [7] => 21 ) )

Nice, it means a form is working. Now use this code (I added for loop and removed implode stuffs). Check if that is what you want

<?php

if (isset($_POST['numbers'])){ 
    $numbers = $_POST['numbers'];
	$big = max($numbers);  
	$small = min($numbers);
	$average = array_sum($numbers) / count($numbers);
	
	print "<font color='LightSlateGrey'><strong>Original Sequence:</strong><br>";
	foreach($numbers as $num){
	    print $num."<br />"
	} 
	print "</font>";
	
	print "<br><font color='green'>Largest Number: $big</font><br>";
	print "<font color='purple'>Smallest Number: $small</font><br>";
	print "<font color='aqua'>Average Number: $average<br></font><br>";
	
}

That doesnt help, all it does is output the sorted numbers horizontally. Am i not being clear enough? As of now my output looks like this:


Original Sequence: Array
Sorted Numbers: 16 7 9 12 17 34 65 99
Largest Number: 99
Smallest Number: 6
Average Number: 31.125

I need the Original Sequence to output the numbers in the order entered by the user, not "Array", also on the "sorted numbers" row their shouldnt be a "1" in front of the output because the lowest number is "6" not "16"

Hope that explains my dilemma a bit more

Original Sequence: Array
Sorted Numbers: 16 7 9 12 17 34 65 99
Largest Number: 99
Smallest Number: 6
Average Number: 31.125

first your question is not clear as for what you want to archieve and how you try to. That being said in my code there is no Sorted number and I wonder why would foreach loop print "Array"

Well i don't know any other way to explain it to you, i think i was clear enough, the sorted number has been in my code the entire time. all i needed was to be able to print the numbers from the form's textboxes in the order that the user inputs them.

can you attach screenshot of your textbox and explain from there?

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.