Jump to content

[SOLVED] array problem


StefanRSA

Recommended Posts

I am not sure how this should work but am sure its got something to do with arrays.

$activetab=$_GET['countrytabs'];
$atabname[0]='MY ADS';
$alink[0]='member/member.php?adminads=true&countrytabs=0';
$atabname[1]='ACCOUNT DETAILS';
$alink[1]='member/member.php?adminads=true&countrytabs=1';
$atabname=[2]'TAGGED ADS';
$alink=[2]'member/member.php?adminads=true&countrytabs=2';

How do I display or echo only those links that is not given by $activetab ?

In other words If

$activetab==0

I want only to echo

$atabname[1]='ACCOUNT DETAILS';
$alink[1]='member/member.php?adminads=true&countrytabs=1';
$atabname=[2]'TAGGED ADS';
$alink=[2]'member/member.php?adminads=true&countrytabs=2';

and so on. I can hardcode this but know there should be a short way in doing this seeing that there is a lot of coding to be done if I have say 20 entries in an array but am not sure how?

 

Example of my hardcoded version:

$activetab=$_GET['countrytabs'];
$atabname[0]='MY ADS';
$alink[0]='member/member.php?adminads=true&countrytabs=0';
$atabname[1]='ACCOUNT DETAILS';
$alink[1]='member/member.php?adminads=true&countrytabs=1';
$atabname=[2]'TAGGED ADS';
$alink=[2]'member/member.php?adminads=true&countrytabs=2';
IF ($activetab==0){
echo $atabname[1];
echo $alink[1];
echo $atabname[2];
echo $alink[2];
}
else if ($activetab==1){
echo $atabname[0];
echo $alink[0];
echo $atabname[2];
echo $alink[2];
}
else {
echo $atabname[0];
echo $alink[0];
echo $atabname[1];
echo $alink[1];
}

Can anybody please help?

Link to comment
Share on other sites

try

<?php
$activetab=$_GET['countrytabs'];
$atabname[0]='MY ADS';
$alink[0]='member/member.php?adminads=true&countrytabs=0';
$atabname[1]='ACCOUNT DETAILS';
$alink[1]='member/member.php?adminads=true&countrytabs=1';
$atabname[2]='TAGGED ADS';
$alink[2]='member/member.php?adminads=true&countrytabs=2';
foreach ($atabname as $key => $name){
if ($key != $activetab){
	echo $name, ' - ', $alink[$key], "<br />\n";
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.