Claim your Biolink Click Here
0 like 0 dislike
11.0k views
Guys pls help me out..i am new to php.. so need help..how can i insert an element in an array through user input(textbox) ,actually numbers,and then sort them in php code????
in Computers & Internet by
retagged | 11.0k views

2 Answers

0 like 0 dislike
<?php
if($_GET['d'] == '2'){
	header("Content-Type: text/plain");
	$_input = $_POST['input'];
	
	foreach($_input as $key => $name) {
	   echo "input[".$key."] = ".$name . "\n";
	}
}else{
?>
<form action="?d=2" method="post">
<input type="text" value="first value" name="input[]">
<input type="text" value="second value" name="input[]">
<input type="submit" value="submit">
</form>
<?php }?>
by
0 like 0 dislike

And for sorting you can use usort()

<?php
function cmp($a, $b)
{
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}

$a = array(3, 2, 5, 6, 1);

usort($a, "cmp");

foreach ($a as $key => $value) {
    echo "$key: $value\n";
}
?>

The above example will output:

0: 1
1: 2
2: 3
3: 5
4: 6

by

Related questions

0 like 0 dislike
1 answer
1 like 0 dislike
0 answers
1 like 0 dislike
0 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

1,310 questions
1,471 answers
569 comments
4,809 users