Jump to content

Question: Make array to display in reverse order?


niclipse

Recommended Posts

I come from a classic ASP 3.0 background, but have now been filling in for our web developer at my company since his lay off. My question is how do I get this array to display in reverse order so the last item renders as the first?

 

$tabs = array();

$tabs[0]["tabtext"] = "Webcasts";
$tabs[0]["viewall_text"] = "More Webcasts...";
$tabs[0]["viewall_url"] = "$com_domain/events";
$tabs[0]["viewall_target"] = "_self";
$tabs[0]["viewall_title"] = "More Webcasts...";

$tabs[1]["tabtext"] = "Events";
$tabs[1]["viewall_text"] = "More Events...";
$tabs[1]["viewall_url"] = "$com_domain/events";
$tabs[1]["viewall_target"] = "_self";
$tabs[1]["viewall_title"] = "More Events...";

$tabs[2]["tabtext"] = "Training";
$tabs[2]["viewall_text"] = "More Classes...";
$tabs[2]["viewall_url"] = "$com_domain/services/training";
$tabs[2]["viewall_target"] = "_self";
$tabs[2]["viewall_title"] = "More Classes...";

Actually, $tabs is a bad example, my web developer hard corded the output rather than let tabs get dynamically generated.

 

A better example would be $webcast, please help me with the below example:

 

$webcast = array();

$webcast[1]["title"] = "PHP Freaks Help Niclipse";
$webcast[1]["day"] = "28";
$webcast[1]["month"] = "jan";
$webcast[1]["url"] = "http://www.yahoo.com/index.html";
$webcast[1]["linktext"] = "Register Now";
$webcast[1]["target"] = "_blank";
$webcast[1]["anchor"] = "phpfreaks";

$webcast[2]["title"] = "PHP Freaks Help Me Again";
$webcast[2]["day"] = "04";
$webcast[2]["month"] = "nov";
$webcast[2]["url"] = "http://www.google.com/index.php";
$webcast[2]["linktext"] = "Register";
$webcast[2]["target"] = "_blank";
$webcast[2]["anchor"] = "phphelp";

 

and this is what I've tried to do, but it isn't working:

 

$webcastReversed = $webcast;
krsort($webcastReversed);
var_dump($webcastReversed);

$webcastReversed = array_reverse( $webcast, true );
var_dump($webcastReversed);

$webcast[1]["title"] = "PHP Freaks Help Niclipse";
$webcast[1]["day"] = "28";
$webcast[1]["month"] = "jan";
$webcast[1]["url"] = "http://www.yahoo.com/index.html";
$webcast[1]["linktext"] = "Register Now";
$webcast[1]["target"] = "_blank";
$webcast[1]["anchor"] = "phpfreaks";

$webcast[2]["title"] = "PHP Freaks Help Me Again";
$webcast[2]["day"] = "04";
$webcast[2]["month"] = "nov";
$webcast[2]["url"] = "http://www.google.com/index.php";
$webcast[2]["linktext"] = "Register";
$webcast[2]["target"] = "_blank";
$webcast[2]["anchor"] = "phphelp";


for($webcastdata = 1; $webcastdata <= sizeof($webcast); ++$webcastdata) {
if($even) {
	$banding = "_even";
	$mouseovering = "onMouseOver=\"style.backgroundColor='#e3e3e3';\" onmouseout=\"style.backgroundColor='#ededed'\"";
	$even = false;
} else {
	$banding = "_odd";
	$mouseovering = "onMouseOver=\"style.backgroundColor='#e3e3e3';\" onmouseout=\"style.backgroundColor='#f9f9f9'\"";
	$even = true;
}

if($webcast[$webcastdata]["target"] == "_blank") {
	$tableUnderloader = "onclick=\"javascript:popUpPage('" . $webcast[$webcastdata]["url"] . "');location.href='$com_domain/events/#" . $webcast[$webcastdata]["anchor"] . "'\"";
} else {
	$tableUnderloader = "onclick=\"location.href='" . $webcast[$webcastdata]["url"] . "#" . $webcast[$webcastdata]["anchor"] . "'\"";
}

$calImage_top = "<img src=\"$com_domain/images/home_dtb/calendar/cal_" . $webcast[$webcastdata]["month"] . ".png\" width=\"33\" height=\"16\" border=\"0\">";
$calImage_bottom = "<img src=\"$com_domain/images/home_dtb/calendar/cal_" . $webcast[$webcastdata]["day"] . ".png\" width=\"33\" height=\"19\" border=\"0\">";		

$calIconTable = "<div style=\"text-align: center; padding: 5px 0px 5px 0px;\">";
$calIconTable .= "$calImage_top<br />$calImage_bottom";
$calIconTable .= "</div>";

$webCastContent .= "<table class=\"caltable$banding\" border=\"0\" $mouseovering $tableUnderloader cellpadding=\"0\" cellspacing=\"0\" width=\"242\" height=\"48\" title=\"" . $webcast[$webcastdata]["title"] . "\">";
$webCastContent .= "<tr><td width=\"45\">$calIconTable";
$webCastContent .= "</td><td width=\"197\">";
$webCastContent .= $webcast[$webcastdata]["title"] . "<br><a href=\"#\"  title=\"" . $webcast[$webcastdata]["linktext"] . "\">" . $webcast[$webcastdata]["linktext"] . "</a>";
$webCastContent .= "</td></tr></table>";

}

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.