FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » foreach in reverse
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: foreach in reverse [message #174193 is a reply to message #174184] Thu, 26 May 2011 11:59 Go to previous messageGo to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
Senior Member
On 5/25/2011 1:11 AM, Evolution wrote:
> On May 24, 6:40 pm, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 5/24/2011 8:43 PM, Evolution wrote:
>>
>>
>>
>>
>>
>>> I wrote the following code to include a succession of 7 files on my
>>> news page and it works fine. However, if I create a new news brief,
>>> it should be indexed 7 and appear at the top of the page. I am
>>> guessing that I would probably have to use a for loop and not foreach
>>> so that I start with the highest index and decrement down (where
>>> 110106_Valentine (below) would be indexed 0), is that the only way?
>>
>>> <?php
>>> session_register();
>>> session_start();
>>> $docRoot = getenv("DOCUMENT_ROOT");
>>
>>> $newsbrief[0] = "110422_Mendes";
>>> $newsbrief[1] = "110411_Livsey";
>>> $newsbrief[2] = "110404_Archuleta";
>>> $newsbrief[3] = "110315_Tanimoto";
>>> $newsbrief[4] = "110312_Ji";
>>> $newsbrief[5] = "110215_Lea";
>>> $newsbrief[6] = "110106_Valentine";
>>
>>> foreach ( $newsbrief as $filename )
>>> {
>>> print "<div class='news'>\n";
>>> require_once $docRoot . '/news/' . $filename . '.php';
>>> print "</div>\n\n";
>>> }
>>> ?>
>>
>>> Also, I read somewhere that session_register() and session_start() are
>>> depricated and should not be used. However, when removed them, some
>>> code seems to have stopped working. Below is an example of how I've
>>> been using session_register() and session_start(). What code would
>>> be proper here?
>>
>>> session_register();
>>> session_start();
>>> $html_title="UCSB Earth Science : Home";
>>> $_SESSION['html_title'] = $html_title;
>>
>>> Thanks a bunch.
>>
>> http://us3.php.net/manual/en/function.array-reverse.php
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Thank you! It worked perfectly!

Another thing to note is that _if_ the elements of the array are being
filled from a SQL call, you could simply have an "ORDER BY ID DESC" at
the end of the call where ID is the autoincrement index that is created
when you added each element to the table. Then your foreach would work
right away.

--
Shelly
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: problem saving date fields
Next Topic: furniture
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 18:15:40 GMT 2024

Total time taken to generate the page: 0.04203 seconds