-1

This code is not working well

How can I fix it ? :)

i got error on this line

if($_GET["id"] === "2")

Here's is the code

<?php if($_GET["id"] === "1")
    print $link1

if($_GET["id"] === "2")
    print $link2    

$link1 = "Link1";

$link2 = "Link2";

4

3 回答 3

0

=== check the type of the operators too. If you just want to compare the two strings use == The object returned by $_GET["id"] may not be of the same type as the String "1"

于 2013-07-24T22:36:40.123 回答
0

=== is an Identical compare operator, meaning that the items being compared must be of the same type.

$_GET["id"] === "2" 

is TRUE if $_GET["id"] is equal to "2", and they are both strings.

Source: http://php.net/manual/en/language.operators.comparison.php

于 2013-07-24T22:37:45.783 回答
0

I'm just going to go ahead and clean it up a bit, I'm not entirely sure what you are trying to accomplish but I can assume it is supposed to look like:

<?php

$link1 = "Link1";
$link2 = "Link2";

if($_GET["id"] == "1") {
 print $link1;
}
if($_GET["id"] == "2") {
 print $link2;
}
于 2013-07-24T22:37:48.823 回答