使用 PHP 的超全局 GET
Superglobal GET using PHP
我是 php 的新手,我无法在堆栈中找到答案。我正在试验并试图弄清楚如何使用超全局 GET 来显示图像并根据用户在 URL.
中修改它的方式更改 *count
我想更改海滩图片 count 次。
所以 URL 看起来像这样:
网站。com/table?beach_image=2&count=4
并且会显示海滩图像 #2,4 次:
bathing suit
<?php
$beach = ['sunglasses.jpg','suncreen.jpg','bathing-suit.jpg','hat.jpg'];
$count = 1;
$beach_image = filter_input(INPUT_GET,"beach_image");
?>
我的 html:
<table>
<tr>
<th>Beach Image</th>
<th>Beach</th>
</tr>
<tr>
<td>0</td>
<td>Sunglasses</td>
</tr>
<tr>
<td>1</td>
<td>Sunscreen</td>
</tr>
<tr>
<td>2</td>
<td>Bathing Suit</td>
</tr>
<tr>
<td>3</td>
<td>Hat</td>
</tr>
</table>
<div>
<img src="images/<?= $beach[$beach_image]?>">
</div>
你可以像下面那样做
<?php
$beach = ['sunglasses.jpg','suncreen.jpg','bathing-suit.jpg','hat.jpg'];
$keysArr = array_fill(0,count($beach),0);//array_combine(array_keys($beach),array_fill(0,count($beach),0));
$beach_image = filter_input(INPUT_GET,"beach_image");
$count = filter_input(INPUT_GET,"count");
$keysArr[$beach_image] = $count;
?>
<table>
<tr>
<th>Beach Image</th>
<th>Beach</th>
</tr>
<tr>
<td><?php echo $keysArr[0] ;?></td>
<td>Sunglasses</td>
</tr>
<tr>
<td><?php echo $keysArr[1] ;?></td>
<td>Sunscreen</td>
</tr>
<tr>
<td><?php echo $keysArr[2] ;?></td>
<td>Bathing Suit</td>
</tr>
<tr>
<td><?php echo $keysArr[3] ;?></td>
<td>Hat</td>
</tr>
</table>
<div>
<?php for($i=1;$i=$count;$i++){?>
<img src="images/<?= $beach[$beach_image]?>">
<?php }?>
</div>
我是 php 的新手,我无法在堆栈中找到答案。我正在试验并试图弄清楚如何使用超全局 GET 来显示图像并根据用户在 URL.
中修改它的方式更改 *count我想更改海滩图片 count 次。
所以 URL 看起来像这样: 网站。com/table?beach_image=2&count=4
并且会显示海滩图像 #2,4 次: bathing suit
<?php
$beach = ['sunglasses.jpg','suncreen.jpg','bathing-suit.jpg','hat.jpg'];
$count = 1;
$beach_image = filter_input(INPUT_GET,"beach_image");
?>
我的 html:
<table>
<tr>
<th>Beach Image</th>
<th>Beach</th>
</tr>
<tr>
<td>0</td>
<td>Sunglasses</td>
</tr>
<tr>
<td>1</td>
<td>Sunscreen</td>
</tr>
<tr>
<td>2</td>
<td>Bathing Suit</td>
</tr>
<tr>
<td>3</td>
<td>Hat</td>
</tr>
</table>
<div>
<img src="images/<?= $beach[$beach_image]?>">
</div>
你可以像下面那样做
<?php
$beach = ['sunglasses.jpg','suncreen.jpg','bathing-suit.jpg','hat.jpg'];
$keysArr = array_fill(0,count($beach),0);//array_combine(array_keys($beach),array_fill(0,count($beach),0));
$beach_image = filter_input(INPUT_GET,"beach_image");
$count = filter_input(INPUT_GET,"count");
$keysArr[$beach_image] = $count;
?>
<table>
<tr>
<th>Beach Image</th>
<th>Beach</th>
</tr>
<tr>
<td><?php echo $keysArr[0] ;?></td>
<td>Sunglasses</td>
</tr>
<tr>
<td><?php echo $keysArr[1] ;?></td>
<td>Sunscreen</td>
</tr>
<tr>
<td><?php echo $keysArr[2] ;?></td>
<td>Bathing Suit</td>
</tr>
<tr>
<td><?php echo $keysArr[3] ;?></td>
<td>Hat</td>
</tr>
</table>
<div>
<?php for($i=1;$i=$count;$i++){?>
<img src="images/<?= $beach[$beach_image]?>">
<?php }?>
</div>