Jump to content

assigning multiple values to one variable


jhodara

Recommended Posts

Hi folks,

 

I was wondering how to do this. I want the if statement to detect if the query string has any of these values. so im trying to assign them all to the same variable. However, this code wont work. Whats the trick here?

 

<?php
$primary=$_GET['intro'];
$primary=$_GET['port'];
$primary=$_GET['about'];
$primary=$_GET['contact']; 

         if(isset($primary)){
     echo "<img src='graphics/left-a.png'>";}
else {echo "<img src='graphics/leftb.png'>";}?>

I *think* this is what you really want to do

if(isset($_GET['intro']) || isset($_GET['port']) || isset($_GET['about']) || isset($_GET['contact']))
{
    echo "<img src='graphics/left-a.png'>";
}
else
{
    echo "<img src='graphics/leftb.png'>";
}

<?php
$primary=array();
if(isset($_GET['intro'])){
$primary['intro']=$_GET['intro'];
$primarykeys[]='intro';
}
if(isset($_GET['port'])){
$primary['port']=$_GET['port'];
$primarykeys[]='port';
}
if(isset($_GET['about'])){
$primary['about']=$_GET['about'];
$primarykeys[]='about';
}
if(isset($_GET['contact'])){
$primary['contact']=$_GET['contact'];
$primarykeys[]='contact';
}
if(count($primary)>0){
echo '<img src="graphics/left-a.png">';
}else{
echo '<img src="graphics/leftb.png">';
}
?>

 

Would this be what you want?

As here you can actually use the get data later on, and no need to check if they exist anymore.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.