Bottyz Posted October 31, 2009 Share Posted October 31, 2009 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 More sharing options...
Daniel0 Posted October 31, 2009 Share Posted October 31, 2009 array_reverse Link to comment https://forums.phpfreaks.com/topic/179748-reversing-a-reversed-array/#findComment-948380 Share on other sites More sharing options...
Bottyz Posted November 1, 2009 Author Share Posted November 1, 2009 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. Link to comment https://forums.phpfreaks.com/topic/179748-reversing-a-reversed-array/#findComment-948659 Share on other sites More sharing options...
kenrbnsn Posted November 1, 2009 Share Posted November 1, 2009 Since this line is reversing the array now: <?php foreach( array_reverse($this->exhibit) as $n ){ ?> Just change it to <?php foreach( $this->exhibit as $n ){ ?> to leave the array in its original order. Ken Link to comment https://forums.phpfreaks.com/topic/179748-reversing-a-reversed-array/#findComment-948670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.