English 中文(简体)
a. 使用或操作不从事菜单
原标题:using or operator not working for menu
  • 时间:2010-05-03 04:58:11
  •  标签:
  • php

我在此守则中,我有一个称为“积极”的科斯班,如果“GET[网页]=辅导、php、我的仪表等,我就使用这一班。

问题在于,即使页数与任何这些数值不相等,但本案的图兰州仍然出于某种原因活跃。

Any ideas why this would be happening? Am I using the or (||) operand incorrectly?

<?php if($_GET[ page ] ==  tutorials  ||  php  ||  mysql  ||  html  ||  css  ||  js ) { ?>
      <li class="active"> <?php } else { ?> <li> <?php } ?>

      <a href="index.php?page=tutorials">Tutorials</a>
        <ul>
     <li><a href="index.php?page=php">PHP</a></li>
     <li><a href="index.php?page=mysql">MySQL</a></li>
     <li><a href="index.php?page=html">HTML</a></li>
     <li><a href="index.php?page=css">CSS</a></li>
     <li><a href="index.php?page=js">JS</a></li>
        </ul>
        </li>
最佳回答

页: 1

你们需要单独测试每一种情况,以便采用这种方式。 因此,你可以:

<?php if($_GET[ page ] ==  tutorials  || $_GET[ page ] ==  php  || $_GET[ page ] ==  mysql  || $_GET[ page ] ==  html  || $_GET[ page ] ==  css  || $_GET[ page ] ==  js ) { ?>

这里是一位候补国家:

<?php
  if(in_array($_GET[ page ], array( tutorials ,  php ,  mysql ,  html ,  css ,  js ))) {
?>

阅读更多有关PHP Control Structures,.arrays , 和codein_array(

问题回答

你可以这样说。 缩略语 (a) 必须重新起草

if ($_GET[ page ] ==  tutorials ) || ($_GET[ page ] ==  php ) || etc....)

你们正在使用“The >不正确”。

Basically what you are doing is testing to see if $_GET[ page ] == tutorials and that is it - each subsequent php , mysql etc evaluates to true. So you get:

$_GET[ page ] || true || true || true || true

简化。 your一阵,看是否存在。

$pages = array( tutorials ,  php ,  mysql  /* etc */);
if (in_array($_GET[ page ], $pages)) {
    // handle
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签