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
https://forums.phpfreaks.com/topic/181296-solved-array-problem/
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
https://forums.phpfreaks.com/topic/181296-solved-array-problem/#findComment-956371
Share on other sites

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.