jestem początkujący w php i mam pewien problem. miałem do zrobienia zadanie i zrobiłem je wspólnie z kolega informatykiem i wytłumaczył ale niezbyt zrozumiale.... oto to zadanie:
Kod
<?php
$x=isset($_POST['liczba_x']) ? $_POST['liczba_x'] : 1;
$y=isset($_POST['liczba_y']) ? $_POST['liczba_y'] : 0;
if($x>$y){
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/tabela.php" method="post">
liczby x: <input type="text" name="liczba_x" />
liczba y: <input type="text" name="liczba_y" />
<input type="submit" value="Oblicz" />
</form>
</body>
</html>
';
}else{
$value=array();
for($i=0; $i<$x; $i++){
$value[]=rand(0,$y);
}
sort($value);
echo '<div>';
foreach($value as $key => $row){
echo '<div> Liczba nr:'.$key.' to '.$row.'</div>';
}
echo '</div>
$x=isset($_POST['liczba_x']) ? $_POST['liczba_x'] : 1;
$y=isset($_POST['liczba_y']) ? $_POST['liczba_y'] : 0;
if($x>$y){
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/tabela.php" method="post">
liczby x: <input type="text" name="liczba_x" />
liczba y: <input type="text" name="liczba_y" />
<input type="submit" value="Oblicz" />
</form>
</body>
</html>
';
}else{
$value=array();
for($i=0; $i<$x; $i++){
$value[]=rand(0,$y);
}
sort($value);
echo '<div>';
foreach($value as $key => $row){
echo '<div> Liczba nr:'.$key.' to '.$row.'</div>';
}
echo '</div>
wiem co ten kod robi (losuje 5 liczb (x) ze zbioru liczb (y)). że jest tu zastosowana pętla if... else... , ale nie zbyt ogarniam co tu sie po kolei dzieje. może ktoś logicznie wytłumaczyć co sie dzieje na poszczególnych etapach?