Forum Moderators: coopster
Function link($link) {
$link1 = array('thisLink1' ,'thatLink1' ,'theOtherLink1' , 'anotherLink1', 'lastLink1');
$link2 = array('thisLink2' ,'thatLink2' ,'theOtherLink2' , 'anotherLink2', 'lastLink2');
if(in_array($link, $link1) {
$newLink = 'http://www.whereiwanttogo1.com';
}
elseif(in_array($link, $link2)) {
$newLink = 'http://www.whereiwanttogo2.com';
}
else {
$newLink = ''; //default link here if it's not found at all
}
return $newLink;
}
function link($link) {
$link1 = 'http://www.link1.com';
$link2 = 'http://www.link2.com';
$link3 = 'http://www.link3.com';
$link4 = 'http://www.link4.com';
$link4 = 'http://www.link4.com';
$linkList = array(
'linkKey1' => $link1,
'linkKey2' => $link1,
'linkKey3' => $link4,
'linkKey4' => $link2,
'linkKey5' => $link3,
'linkKey6' => $link3,
'linkKey7' => $link1,
'linkKey8' => $link2,
'linkKey9' => $link2,
'linkKey10' => $link4
);
If(in_array($link, $linkList, true) {
return $linkList[$link];
}
else {
return 'Link not found'; //or some other not found handler
}
}
Then I wondered why I simply could not do if ($var == "link1 || link2") {$link = "http://www.example.com/";}
and could not find a definite answer (my guess is that all under one pair of quotes counts as one value),
if (strstr('link1,link2',$var)) {$link = "http://www.example.com/";}
if (strpos('link1,link2',$var) != false) {$link = "http://www.example.com/";}
if (strpos('@link1,link2',$var)) {$link = "http://www.example.com/";}
if ( !in_array($var, array('link1','link2'), true ) ) {$link = "http://www.example.com/";}