1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title></title>
5 <meta charset="utf-8">
6 </head>
7 <body>
8 <form action="" method="get">
9 <select name="select_option"> //html语法:<select><option></option></select>
10 <option value="">请选择城市</option>//默认第一个显示为:请选择城市
11 <option value="北京">北京</option>
12 <option value="上海">上海</option>
13 <option value="广州">广州</option>
14 <option value="深圳">深圳</option>
15 <option value="大连">大连</option>
16 </select>
17 <input type="submit" value="点击">
18 </form>
19 <?php
20 header("Content-Type:text/html;charset=utf-8");
21 $selected=isset($_GET["select_option"])?$_GET["select_option"]:"";
//isset — 检测变量是否已设置并且非空

表达式? 条件1 :条件二

如果表达式为真就返回条件1,如果为假就返回条件2.

isset() 函数

isset用来判断函数变量是否存在。

$action=isset($_GET['id']) ? $_GET['id'] : '';

这句话的意思就是:如果$_GET['id']已经被设置,即已经有值了,则将$_GET['id']赋给$action;

如果$_GET['id']没有被设置,则$action='';

22        echo $selected;
23 ?>
24
25 </body>
26 </html>

显示结果:

关于PHP的isset()函数的更多相关文章

  1. [PHP源码阅读]empty和isset函数

    近日被问到PHP中empty和isset函数时怎么判断变量的,刚开始我是一脸懵逼的,因为我自己也只是一知半解,为了弄懂其真正的原理,赶紧翻开源码研究研究.经过分析可发现两个函数调用的都是同一个函数,因 ...

  2. empty和isset函数详解

    1.empty函数 用途:检测变量是否为空 若变量不存在则返回 TRUE 若变量存在且其值为"".0."0".NULL..FALSE.array().var $ ...

  3. PHP isset 函数作用

    isset函数是检测变量是否设置. 格式:bool isset ( mixed var [, mixed var [, ...]] ) 返回值: 若变量不存在则返回 FALSE 若变量存在且其值为NU ...

  4. php 中 isset()函数 和 empty()函数的区别

    首先这两个函数都是用来测试变量的状态: isset()函数判断一个变量是否在 如果存在返回true  否则返回false empty()函数判断一个变量是否为空,如果为空返回true 否则返回fals ...

  5. (转载)PHP isset()函数作用

    (转载)http://www.cnblogs.com/neve/archive/2011/03/21/1990165.html isset函数是检测变量是否设置. 格式:bool isset ( mi ...

  6. php中empty和isset函数

    函数使用格式 empty bool empty ( mixed $var ) 判断变量是否为空. isset bool isset ( mixed $var [ , mixed $... ] ) 判断 ...

  7. PHP的isset()函数 一般用来检测变量是否设置

    PHP的isset()函数 一般用来检测变量是否设置 格式:bool isset ( mixed var [, mixed var [, ...]] ) 功能:检测变量是否设置 返回值: 若变量不存在 ...

  8. PHP isset() 函数

    isset() 函数用于检测变量是否已设置并且非 NULL.高佣联盟 www.cgewang.com 如果已经使用 unset() 释放了一个变量之后,再通过 isset() 判断将返回 FALSE. ...

  9. php中empty(), is_null(), isset()函数区别

    empty(), is_null(), isset()真值表(区别) 我们先来看看这3个函数的功能描述 www.111cn.net isset 判断变量是否已存在,如果变量存在则返回 TRUE,否则返 ...

  10. php中empty(), is_null(), isset()函数区别(转)

    empty(), is_null(), isset()真值表(区别)   我们先来看看这3个函数的功能描述 www.111cn.net isset 判断变量是否已存在,如果变量存在则返回 TRUE,否 ...

随机推荐

  1. postcss 运用及原理

    postcss 入坑指南 目标: 掌握 postcss 的使用 自定义 postcss 插件 掌握 stylelint 的使用 自定义 stylelint rule 扩展 css parser 解释器 ...

  2. 1.ASP.NET Core 管道、中间件、依赖注入

    自定义中间件(基于工厂) 自定义中间件(注入到第三方容器)

  3. 仿射加密与S-DES加密算法的实现

    仿射加密 #include <iostream> #include <cstdio> using namespace std; char letter[30]; char _l ...

  4. gradle中的增量构建

    目录 简介 增量构建 自定义inputs和outputs 运行时API 隐式依赖 输入校验 自定义缓存方法 输入归一化 其他使用技巧 gradle中的增量构建 简介 在我们使用的各种工具中,为了提升工 ...

  5. when I was installing github for windows ,some errors occurred !

    1: 2: 3: 4: install.log error messages:

  6. Linux command find All In One

    Linux command find All In One $ find -h # find: illegal option -- h # usage: # find [-H | -L | -P] [ ...

  7. website i18n and L10n all in one

    website i18n and L10n all in one Localization & Internationalization 本地化 & 国际化 https://www.w ...

  8. how to write an ebook that can support published by format PDF, Epub, Mobi and so on

    how to write an ebook that can support published by format PDF, Epub, Mobi and so on 如何写一本自己的电子书,支持各 ...

  9. 宝塔部署Nestjs

    1. 在宝塔上下载pm2 2. 打包你的服务端代码 "npm run build && cp ./package.json ./dist/" 3. 在宝塔文件&qu ...

  10. vux使用

    Vue中使用vux的配置,分为两种情况: 一.根据vux文档直接安装,无需手动配置 npm install vue-cli -g // 如果还没安装 vue init airyland/vux2 my ...