传递两个参数,并使用php$\u GET[]代码获取它们
在第一页:传递两个参数,并使用php$\u GET[]代码获取它们,php,arguments,Php,Arguments,在第一页: <?php $post_id=123467890; $post_status="publish"; ?> <a href="temp_views/post_view.php?postid=<?php echo $post_id;?>&status=<?php echo $post_status;?>" target="_blank" style="color: darkgreen;"><i class="fas fa-e
<?php
$post_id=123467890;
$post_status="publish";
?>
<a href="temp_views/post_view.php?postid=<?php echo $post_id;?>&status=<?php echo $post_status;?>" target="_blank" style="color: darkgreen;"><i class="fas fa-external-link-alt"></i></a>
isset()
函数返回TRUE
如果var存在并且值不是NULL
<代码>错误否则
试试这个
echo $_post_id = isset($_GET['post_id'])?$_GET['post_id']:""; // this give me 123467890 that is
//correct
echo $_post_status = isset($_GET['status'])?$_GET['status']:""; // this giving me 1 why?
阅读isset()
始终给出true或false<代码>isset()用于检查值是否设置为变量。如果您想获得值,那么必须在if条件中添加$\u get['status'],如示例所示
if(isset($_GET['status'])) {
$_post_status= $_GET['status']
}
在PHP7+中,您可以使用
$\u post\u status=$\u GET['post\u id']代码>(空合并运算符)
if(isset($_GET['status'])) {
$_post_status= $_GET['status']
}