Jump to content

Reversing A Reversed Array?


Bottyz

Recommended Posts

Hi all,

 

 

How can i unreverse or double-reverse the following script? I want the script to read from a text file but with the ID going up not down.

 

 

	function display(){
	global $EXHIBIT_ITEM, $EXHIBIT_LIST, $JAVASCRIPT;
	$CODE_URL = exhibit_CODE_URL;

	$view = '';
	$items = '';
	$itemId = count($this->exhibit) + 1;

	// ORDER IN REVERSE
	reset( $this->exhibit );
	foreach( array_reverse($this->exhibit) as $n ){
		$itemId--;
		if( $this->isLoggedIn() ){
			$editLinks = <<<EOT
<A HREF="#" ONCLICK="exhibit_ShowElement('exhibit-edit-$itemId'); exhibit_HideElement('exhibit-view-$itemId'); return false;"><b>Edit</b></A> | 
<A HREF="$CODE_URL?exhibit_action=delete&id=$itemId" ONCLICK="return confirm('Are you sure you want to delete this exhibition item?')"><b>Delete</b></A>
EOT;
			}
		else {
			$editLinks = '';
			}

		$formExhibition = htmlentities( $n['exhibition'] );
		$formStartdate = htmlentities( $n['startdate'] );
		$formEnddate = htmlentities( $n['enddate'] );
		$formVenue = htmlentities( $n['venue'] );
		$replaces = array(
			'{EXHIBITION}'			=> $n['exhibition'],
			'{FORM_EXHIBITION}'		=> $formExhibition,
			'{STARTDATE}'			=> $n['startdate'],
			'{FORM_STARTDATE}'		=> $formStartdate,
			'{ENDDATE}'			=> $n['enddate'],
			'{FORM_ENDDATE}'		=> $formEnddate,
			'{VENUE}'			=> $n['venue'],
			'{FORM_VENUE}'			=> $formVenue,
			'{ITEM_ID}'			=> $itemId,
			'{EDIT_LINKS}'			=> $editLinks,
			'{CODE_URL}'			=> exhibit_CODE_URL
			);
		$itemDisplay = str_replace( array_keys($replaces), array_values($replaces), $EXHIBIT_ITEM );
		$items .= $itemDisplay;
		}

Link to comment
https://forums.phpfreaks.com/topic/179748-reversing-a-reversed-array/
Share on other sites

Thanks for your reply Daniel but if i remove the code withing the array_reverse brackets i get an invalid arguement error.

 

I only want to reverse the order of the list as its taken from the file. At the minute it is taking the first entry and putting it last. But i want it to put the first entry in the text file first.

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.