By GokiSoft.com|
19:34 05/01/2024|
Học PHP
Sinh ngẫu nhiên mảng gồm N số nguyên trong PHP - Sắp xếp mảng trong PHP
Sinh ngẫu nhiên mảng gồm N số nguyên có giá trị từ 1-100
Sắp xếp mảng theo thứ tự tăng dần và hiển thị kết quả ra màn hình
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![nguyễn văn huy [T1907A]](https://www.gravatar.com/avatar/b107d14d7d43c142b68c12c377262371.jpg?s=80&d=mm&r=g)
nguyễn văn huy
2020-06-14 13:26:42
<?php
$rand=mt_rand(0,100);
echo $rand.'<br/>';
$dayso=[];
for ($i=0; $i <$rand ; $i++) {
# code...
$dayso[$i]=mt_rand(0,100);
}
for ($i=0; $i < count($dayso); $i++) {
# code...
echo $dayso[$i] . " ";
}
?>
![Trương Công Vinh [T1907A]](https://www.gravatar.com/avatar/223a7e3a46f4a747f81b921fe023fcc4.jpg?s=80&d=mm&r=g)
Trương Công Vinh
2020-06-13 02:15:00
<?php
$int = [];
for ($i=0; $i <rand(9,999) ; $i++) {
// code...
$int[] = rand(1,999);
}
echo "START : </br>";
foreach ($int as $n) {
// code...
echo ",".$n;
}
echo "</br>";
sort($int);
echo "END : </br>";
foreach ($int as $n) {
// code...
echo ",".$n;
}
?>
![Minh Nghia [T1907A]](https://www.gravatar.com/avatar/ecca255d725eed36a872105205af1b8e.jpg?s=80&d=mm&r=g)
Minh Nghia
2020-06-12 15:12:38
<!DOCTYPE html>
<html>
<head>
<title>Arrange the array element in php</title>
</head>
<body>
<?php
$random = mt_rand(1,100);
echo "Mang ngau nhien $random : <br/>";
$arrlist = [];
for ($i=1; $i <= $random; $i++) {
$number = mt_rand(1,100);
$arrlist[] = $number;
echo $number.',';
}
sort($arrlist);
echo "<br/>Mang sau khi duoc sap xep : <br/> ";
foreach ($arrlist as $n) {
echo "$n ";
}
?>
</body>
</html>
![Phí Văn Long [T1907A]](https://www.gravatar.com/avatar/5db166b7b74443c5c221e4c0068d6da9.jpg?s=80&d=mm&r=g)
Phí Văn Long
2020-06-12 10:04:16
<?php
$random = mt_rand(1,100);
$array = [];
for ($i=0; $i < $random ; $i++) {
$array[$i] = mt_rand(1,100).'-';
}
for ($i=0; $i < count($array) ; $i++) {
print $array[$i];
}
sort($array);
?>
<!DOCTYPE html>
<html>
<head>
<title>Sinh ngẫu nhiên mảng gồm N số nguyên trong PHP - Sắp xếp mảng trong PHP </title>
</head>
<body>
<h1 style="color: red">Sau khi sap xep la : <?=print_r($array)?></h1>
</body>
</html>
![Phan Bạch Tùng Dương [T1907A]](https://www.gravatar.com/avatar/e74e3ec62fe3a191929e12eecbe01edf.jpg?s=80&d=mm&r=g)
Phan Bạch Tùng Dương
2020-06-12 10:04:13
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$rand = mt_rand(1, 100);
echo('Mang ngau nhien: ' . '<br>');
echo $rand;
$arr = [];
for ($i = 0; $i < $rand; $i++) {
$arr[$i] = mt_rand(1, 100);
}
for ($i = 0; $i < count($arr); $i++) {
echo $arr[$i] . " ";
}
sort($arr);
echo "<br>Mang sau khi sap xep: <br/>";
print_r($arr);
?>
</body>
</html>
![Trần Mạnh Dũng [T1907A]](https://www.gravatar.com/avatar/ee4661d1f9133c241d6c8287c7ea8ceb.jpg?s=80&d=mm&r=g)
Trần Mạnh Dũng
2020-06-12 09:57:53
#baitap2.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" <meta
name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
$random = random_int(1, 100);
echo "Random number array: ".$random.'<br/>';
$array = [];
for ($i=1; $i <$random ; $i++) {
$array[$i] = random_int(1, 100);
}
sort($array);
echo'Sort array: ';
for ($i=1; $i < count($array); $i++) {
echo$array[$i]." ";
}
?>
</body>
</html>
![Nguyen Tuan Anh [T1907A]](https://www.gravatar.com/avatar/002096a0be1ae5a481a9e1d00aa8b009.jpg?s=80&d=mm&r=g)
Nguyen Tuan Anh
2020-06-12 09:51:21
<?php
header('Content-type: text/plain');
$array = [];
for ($i=0; $i < 10 ; $i++) {
$array[$i] = rand(1,100);
}
echo "Default ";
print_r($array)."\n";
sort($array);
echo "Sorted Array";
print_r($array);
?>
![Đỗ Văn Huấn [T1907A]](https://www.gravatar.com/avatar/04c40301dd027839d265b3c3c9dc6e6b.jpg?s=80&d=mm&r=g)
Đỗ Văn Huấn
2020-06-12 09:34:13
<?php
$n = rand(1, 100);
echo 'n = '.$n. '<br>';
$intList = array();
for ($i=0; $i < $n ; $i++) {
$number = rand(1,100);
$intList[] = $number;
}
sort($intList);
foreach( $intList as $a) {
echo $a.' ';
}
?>
![Lê Minh Bắc [T1907A]](https://www.gravatar.com/avatar/22abcac77d8ca5e01144e240abb48d22.jpg?s=80&d=mm&r=g)
Lê Minh Bắc
2020-06-12 09:32:06
<!DOCTYPE html>
<html>
<head>
<title>Sắp xếp mảng trong PHP</title>
<meta charset="utf-8">
</head>
<body>
<?php
$ran = mt_rand(1,20);
$number = [];
echo 'Mảng ban đầu: ';
for ($i=1; $i <= $ran ; $i++) {
$ran1 = mt_rand(1,100);
$number[] = $ran1;
echo $ran1.', ';
}
sort($number);
echo '<br>Mảng sau khi sắp xếp: ';
for ($i=0; $i < $ran; $i++) {
echo $number[$i].', ';
}
?>
</body>
</html>
![Luong Dinh Dai [T1907A]](https://www.gravatar.com/avatar/ca08fa4090e1038e541197564747f93c.jpg?s=80&d=mm&r=g)
Luong Dinh Dai
2020-06-12 09:31:29
<?php
$random = random_int(0, 100);
echo $random.'<br/>';
$array = [];
for ($i=0; $i <$random ; $i++) {
$array[$i] = random_int(0, 100);
}
for ($i=0; $i < count($array); $i++) {
}
sort($array);
for ($i=0; $i < count($array); $i++) {
echo $array[$i]." ";
}
?>