I am trying to create a dynamic link, in this way:
- Take an array
- Search for the key of one element
- Delete this element
- Implode the array elements to a string
- Show the string as a parameter in the link
I am doing it like it follows:
$url_langs=array('fra','cat','hun'...); //CURRENT LANGS in use
$all_langs=array('eng','fra','por','ser','cat','dan','hun','fin','est','esl',...);
foreach($all_langs as $lang){
echo (in_array($lang,$url_langs))?'<a href="' . implode('|',unset($url_langs[array_search($lang,$url_langs)])) . '">' . $lang . '</b> ':'<a href="' . implode('|',$url_langs) . '|' . $lang . '">' . $lang . '</a> ';
}
Well, as you can see. I iterate the array which contains all the available languages, and check if it is already in use or not. If it is in use, I show a link to not use it; and the same for the contrary case.
As the php manual (unset) says: "No value is returned.". So I can't use unset on the fly. My questions are:
- Is there any alternative form to achieve it?
- I could use the long
if
sentence, and define a new array which I will then use for the implode() function. But, isn't it strange? Crate a new array if my goal is make it as plain text? - I could use a str_replace to remove this part of the string once imploded... but this I can't do it on the fly, neither.
Thanks a lot.