I have 3 variables holding 3 different values(managed from admin).
$tab_download_pos = 2;
$tab_download_title = "Download";
$tab_overview_pos = 1;
$tab_overview_title = "Overview";
$tab_faq_pos = 3;
$tab_faq_title = "FAQ";
Now I have 3 tabs and I would like to sort the tabs based on the values from above variables.
The three tabs are
1.Overview
2.Download
3.Faq
I started in this way
$tab_arr = sort(array($tab_download_pos,$tab_overview_pos,$tab_faq_pos));
I did foreach loop but then I am lost. I would like to sort the tabs based on the values from the variables which I am getting from backend.
Any help is highly appreciated. Thanks in advance.
No need to sort. Just need to put them in an array, sort it by key with ksort, and iterate over them:
$a = array();
$a[$tab_download_pos] = $tab_download_title;
$a[$tab_overview_pos] = $tab_overview_title;
$a[$tab_faq_pos] = $tab_faq_title;
ksort($a);
foreach($a as $p => $title) {
echo "$p.$title\n";
}
0 comments:
Post a Comment