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
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
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
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
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
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
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
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
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
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
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]." ";
}
?>