Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1846

Re: foreach in reverse

From sheldonlg <sheldonlg@thevillages.net>
Newsgroups comp.lang.php
Subject Re: foreach in reverse
Date 2011-05-26 07:59 -0400
Organization A noiseless patient Spider
Message-ID <irlfbk$vhr$1@dont-email.me> (permalink)
References <54289e0b-89c3-4bc5-9077-77a2568b66fe@q12g2000prb.googlegroups.com> <irhmn8$6qt$1@dont-email.me> <bb509717-28a8-4a78-a81d-e9b73de5caa2@x38g2000pri.googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

foreach in reverse Evolution <cryptozoan@gmail.com> - 2011-05-24 17:43 -0700
  Re: foreach in reverse Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-24 21:40 -0400
    Re: foreach in reverse Evolution <cryptozoan@gmail.com> - 2011-05-24 22:11 -0700
      Re: foreach in reverse sheldonlg <sheldonlg@thevillages.net> - 2011-05-26 07:59 -0400
  Re: foreach in reverse Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-24 21:44 -0400
  Re: foreach in reverse "Peter H. Coffin" <hellsop@ninehells.com> - 2011-05-24 21:01 -0500
    Re: foreach in reverse Helmut Chang <usenet@helmutchang.at> - 2011-05-25 08:05 +0200
  Re: foreach in reverse Helmut Chang <usenet@helmutchang.at> - 2011-05-25 08:19 +0200
  Re: foreach in reverse Denis McMahon <denis.m.f.mcmahon@gmail.com> - 2011-05-25 15:07 +0000

csiph-web