php-general Digest 10 Mar 2012 15:38:02 -0000 Issue 7721

2012-03-10 Thread php-general-digest-help

php-general Digest 10 Mar 2012 15:38:02 - Issue 7721

Topics (messages 316962 through 316962):

Re: questions about $_SERVER
316962 by: Tedd Sperling

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On Mar 9, 2012, at 10:20 PM, Jim Giner wrote:
 tamouse mailing lists tamouse.li...@gmail.com wrote in message 
 news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I 
 know
 if I want to modify $_SERVER myself?
 
 Once your script starts the superglobals are no different to any other 
 variables, except that they're in scope at all times.
 
 That's probably the reason why they are named SuperGlobals. :-)
 
 But to be more descriptive, these are simply globals that are predefined 
 by php -- see:
 
 http://php.net/manual/en/language.variables.superglobals.php
 
 I believe, (please show me otherwise) there are no globals in PHP other 
 than SuperGlobals.
 
 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)
 
 Just to be clear - you asked if it were true that there are no globals in 
 PHP other than SuperGlobals:  Don't forget that anything that you declare as 
 global in a script is a global for that instance of that script (and 
 whatever includes, etc. that it calls during its run) 

That's correct, but to access those variables outside of their scope (such as a 
function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

As such, there are no globals in PHP other than SuperGlobals. As I said, if 
I'm wrong, please show me otherwise.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com
---End Message---


Re: [PHP] questions about $_SERVER

2012-03-10 Thread Tedd Sperling
On Mar 9, 2012, at 10:20 PM, Jim Giner wrote:
 tamouse mailing lists tamouse.li...@gmail.com wrote in message 
 news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I 
 know
 if I want to modify $_SERVER myself?
 
 Once your script starts the superglobals are no different to any other 
 variables, except that they're in scope at all times.
 
 That's probably the reason why they are named SuperGlobals. :-)
 
 But to be more descriptive, these are simply globals that are predefined 
 by php -- see:
 
 http://php.net/manual/en/language.variables.superglobals.php
 
 I believe, (please show me otherwise) there are no globals in PHP other 
 than SuperGlobals.
 
 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)
 
 Just to be clear - you asked if it were true that there are no globals in 
 PHP other than SuperGlobals:  Don't forget that anything that you declare as 
 global in a script is a global for that instance of that script (and 
 whatever includes, etc. that it calls during its run) 

That's correct, but to access those variables outside of their scope (such as a 
function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

As such, there are no globals in PHP other than SuperGlobals. As I said, if 
I'm wrong, please show me otherwise.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-10 Thread Jim Giner

Tedd Sperling tedd.sperl...@gmail.com wrote in message 
news:315faa8f-3103-4661-b167-d30248952...@gmail.com...
On Mar 9, 2012, at 10:20 PM, Jim Giner wrote:
 tamouse mailing lists tamouse.li...@gmail.com wrote in message
 news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I
 know
 if I want to modify $_SERVER myself?

 Once your script starts the superglobals are no different to any other
 variables, except that they're in scope at all times.

 That's probably the reason why they are named SuperGlobals. :-)

 But to be more descriptive, these are simply globals that are predefined
 by php -- see:

 http://php.net/manual/en/language.variables.superglobals.php

 I believe, (please show me otherwise) there are no globals in PHP 
 other
 than SuperGlobals.

 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)

 Just to be clear - you asked if it were true that there are no globals 
 in
 PHP other than SuperGlobals:  Don't forget that anything that you declare 
 as
 global in a script is a global for that instance of that script (and
 whatever includes, etc. that it calls during its run)

That's correct, but to access those variables outside of their scope (such 
as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

As such, there are no globals in PHP other than SuperGlobals. As I said, 
if I'm wrong, please show me otherwise.

Cheers,

tedd
**
Actually - I've never used $GLOBAL - I've just referenced them by their 
name as specified in the global statement - so it's not always obvious 
that a specific var IS a global.I can see thought that you are aware of 
them so my point is unnecessary. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Have little enough hair as it is ...

2012-03-10 Thread Lester Caine

OK this has got to be some configuration problem!
I've two machines running fine Apache 2.2.15/PHP5.3.8 and two not with what
should be identical Apache/PHP setups.
All SUSE machines but 11.3, 11.4 and 12.1 with 11.3 and 11.4 machine running
fine ...

http://piwik.medw.org.uk/phpinfo.php has http://piwik.medw.org.uk/ working 
fine...

http://piwik.rainbowdigitalmedia.org.uk/phpinfo.php is just giving seg faults on 
http://piwik.rainbowdigitalmedia.org.uk/ but http://rainbowdigitalmedia.org.uk/ 
is working perfectly.


The piwik analytics is based on Zend, and I've not been able to get it working 
on either of the two new machines, while all of my other stuff is working fine. 
I started with Apache2.4.1 and PHP5.4.0 and moved back to what should be the 
same versions as the working machines but without success.


ANYBODY got any ideas?
What should I be doing next to try and track down where the seg fault is coming 
from?


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] file url access funniness

2012-03-10 Thread TR Shaw
This is weird.  This statement fails:

$tlds = file(http://www.surbl.org/tld/three-level-tlds;, 
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

Warning: file(http://www.surbl.org/tld/three-level-tlds): failed to open 
stream: HTTP request failed! HTTP/1.0 502 Bad Gateway

also tried the final location and it fails with:

Warning: file(http://george.surbl.org/two-level-tlds): failed to open stream: 
HTTP request failed!  

But a browser and the following work:

$response = shell_exec(curl -s -S -L 
http://data.iana.org/TLD/tlds-alpha-by-domain.txt -o tlds-alpha-by-domain.txt);

Any ideas?  I'd rather not use curl if possible.

TIA,

Tom




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] file url access funniness

2012-03-10 Thread Simon Schick
Hi, TR Shaw

I would next try curl as php-extension.
If that is working well, and you need it definitely with file() I'd use
Wireshark to check which request is sent to the remote machine.

Bye
Simon

2012/3/10 TR Shaw ts...@oitc.com

 This is weird.  This statement fails:

$tlds = file(http://www.surbl.org/tld/three-level-tlds;,
 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

 Warning: file(http://www.surbl.org/tld/three-level-tlds): failed to open
 stream: HTTP request failed! HTTP/1.0 502 Bad Gateway

 also tried the final location and it fails with:

 Warning: file(http://george.surbl.org/two-level-tlds): failed to open
 stream: HTTP request failed!

 But a browser and the following work:

$response = shell_exec(curl -s -S -L
 http://data.iana.org/TLD/tlds-alpha-by-domain.txt -o
 tlds-alpha-by-domain.txt);

 Any ideas?  I'd rather not use curl if possible.

 TIA,

 Tom




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Maciek Sokolewicz

On 09-03-2012 14:11, Daniel Brown wrote:

 (To the list, as well.  First day with my new fingers, apparently)

On Fri, Mar 9, 2012 at 08:09, Daniel Browndanbr...@php.net  wrote:

On Thu, Mar 8, 2012 at 21:23, Tedd Sperlingtedd.sperl...@gmail.com  wrote:

This starts getting a bit off-topic from your original email, but
knowing that you're trying to use it for teaching your classes at the
college, it may be of some value to you.


All of this aside, though, you may instead want to use something along the 
lines of date('d',strtotime('last day of this month')); in tandem with your 
date formatting.


That's a good idea, but


date('d',strtotime('last day of this month'));


gives me the number of days in *this* month, but not the next, or previous, 
month.

I need the result to be whatever date was selected -- something like:

$number_days = date('d',strtotime('last day of April, 2014'));

But that doesn't work.


Sure it does, though you may have some issues when using
punctuation, unnecessary words, or using capital letters for anything
other than proper names.  What version of PHP are you using?  I get
the correct answers for all of the following phrases:

last day of April 2014
last day of this month
last day of next month
last day of last month
third Saturday March 2012

Or you can even be excruciatingly redundant:

echo date('d',strtotime('last day of this
month',strtotime('next month')));
echo date('d',strtotime('last day of this
month',strtotime('February 2018')));
echo date('d',strtotime('second Monday',strtotime('September 2012')));







I must admit I'm still at a loss why people would want a function to 
tell them the amount of days in a month. That amount is pretty much 
fixed (except for february, but that's also mathematically easy to fix). 
So a simple function like:

function getAmountOfDaysInAMonth($month, $year) {
   $days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) 
? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

   return $days[$month+1];
}

Would work just fine. Unless of course you want to count the amount of 
days during the changing of calendars (ie during the change of the 
julian calendar to the gregorian), or in different calendars altogether.


Why (ab)use the datetime library for such a very simple thing? In the 
last case, I would indeed use DateTime, simply because it's not an easy 
answer.

- Tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Have little enough hair as it is ...

2012-03-10 Thread Simon Schick
Hi, Lester

Can you give us some more information?

How is php called in your apache-configuration? (f)cgi, module or somehow else?
You said that the configuration should be the same ... can you
double-check that? Reload the services etc ...

What about the logs? There must be more info in there ...

Bye
Simon

2012/3/10 Lester Caine les...@lsces.co.uk:
 OK this has got to be some configuration problem!
 I've two machines running fine Apache 2.2.15/PHP5.3.8 and two not with what
 should be identical Apache/PHP setups.
 All SUSE machines but 11.3, 11.4 and 12.1 with 11.3 and 11.4 machine running
 fine ...

 http://piwik.medw.org.uk/phpinfo.php has http://piwik.medw.org.uk/ working
 fine...

 http://piwik.rainbowdigitalmedia.org.uk/phpinfo.php is just giving seg
 faults on http://piwik.rainbowdigitalmedia.org.uk/ but
 http://rainbowdigitalmedia.org.uk/ is working perfectly.

 The piwik analytics is based on Zend, and I've not been able to get it
 working on either of the two new machines, while all of my other stuff is
 working fine. I started with Apache2.4.1 and PHP5.4.0 and moved back to what
 should be the same versions as the working machines but without success.

 ANYBODY got any ideas?
 What should I be doing next to try and track down where the seg fault is
 coming from?

 --
 Lester Caine - G8HFL
 -
 Contact - http://lsces.co.uk/wiki/?page=contact
 L.S.Caine Electronic Services - http://lsces.co.uk
 EnquirySolve - http://enquirysolve.com/
 Model Engineers Digital Workshop - http://medw.co.uk//
 Firebird - http://www.firebirdsql.org/index.php

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Matijn Woudt
On Sat, Mar 10, 2012 at 6:20 PM, Maciek Sokolewicz
maciek.sokolew...@gmail.com wrote:
 On 09-03-2012 14:11, Daniel Brown wrote:

     (To the list, as well.  First day with my new fingers, apparently)

 On Fri, Mar 9, 2012 at 08:09, Daniel Browndanbr...@php.net  wrote:

 On Thu, Mar 8, 2012 at 21:23, Tedd Sperlingtedd.sperl...@gmail.com
  wrote:

    This starts getting a bit off-topic from your original email, but
 knowing that you're trying to use it for teaching your classes at the
 college, it may be of some value to you.

 All of this aside, though, you may instead want to use something along
 the lines of date('d',strtotime('last day of this month')); in tandem with
 your date formatting.


 That's a good idea, but

 date('d',strtotime('last day of this month'));


 gives me the number of days in *this* month, but not the next, or
 previous, month.

 I need the result to be whatever date was selected -- something like:

 $number_days = date('d',strtotime('last day of April, 2014'));

 But that doesn't work.


    Sure it does, though you may have some issues when using
 punctuation, unnecessary words, or using capital letters for anything
 other than proper names.  What version of PHP are you using?  I get
 the correct answers for all of the following phrases:

        last day of April 2014
        last day of this month
        last day of next month
        last day of last month
        third Saturday March 2012

    Or you can even be excruciatingly redundant:

        echo date('d',strtotime('last day of this
 month',strtotime('next month')));
        echo date('d',strtotime('last day of this
 month',strtotime('February 2018')));
        echo date('d',strtotime('second Monday',strtotime('September
 2012')));





 I must admit I'm still at a loss why people would want a function to tell
 them the amount of days in a month. That amount is pretty much fixed (except
 for february, but that's also mathematically easy to fix). So a simple
 function like:
 function getAmountOfDaysInAMonth($month, $year) {
   $days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) ? 29 :
 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   return $days[$month+1];
 }

Shouldn't this be $month-1?

- Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Maciek Sokolewicz
On 10 March 2012 19:06, Matijn Woudt tijn...@gmail.com wrote:

 On Sat, Mar 10, 2012 at 6:20 PM, Maciek Sokolewicz
 maciek.sokolew...@gmail.com wrote:
  On 09-03-2012 14:11, Daniel Brown wrote:
 
  (To the list, as well.  First day with my new fingers,
 apparently)
 
  On Fri, Mar 9, 2012 at 08:09, Daniel Browndanbr...@php.net  wrote:
 
  On Thu, Mar 8, 2012 at 21:23, Tedd Sperlingtedd.sperl...@gmail.com
   wrote:
 
 This starts getting a bit off-topic from your original email, but
  knowing that you're trying to use it for teaching your classes at the
  college, it may be of some value to you.
 
  All of this aside, though, you may instead want to use something
 along
  the lines of date('d',strtotime('last day of this month')); in
 tandem with
  your date formatting.
 
 
  That's a good idea, but
 
  date('d',strtotime('last day of this month'));
 
 
  gives me the number of days in *this* month, but not the next, or
  previous, month.
 
  I need the result to be whatever date was selected -- something like:
 
  $number_days = date('d',strtotime('last day of April, 2014'));
 
  But that doesn't work.
 
 
 Sure it does, though you may have some issues when using
  punctuation, unnecessary words, or using capital letters for anything
  other than proper names.  What version of PHP are you using?  I get
  the correct answers for all of the following phrases:
 
 last day of April 2014
 last day of this month
 last day of next month
 last day of last month
 third Saturday March 2012
 
 Or you can even be excruciatingly redundant:
 
 echo date('d',strtotime('last day of this
  month',strtotime('next month')));
 echo date('d',strtotime('last day of this
  month',strtotime('February 2018')));
 echo date('d',strtotime('second Monday',strtotime('September
  2012')));
 
 
 
 
 
  I must admit I'm still at a loss why people would want a function to tell
  them the amount of days in a month. That amount is pretty much fixed
 (except
  for february, but that's also mathematically easy to fix). So a simple
  function like:
  function getAmountOfDaysInAMonth($month, $year) {
$days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) ?
 29 :
  28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
return $days[$month+1];
  }

 Shouldn't this be $month-1?

 - Matijn


Ehr, sorry, yes, you're right; well spotted! :)

- Tul


Re: [PHP] Function mktime() documentation question

2012-03-10 Thread tamouse mailing lists
I'm just a bit baffled why this isn't a standard library function.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-10 Thread tamouse mailing lists
On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 9, 2012, at 10:20 PM, Jim Giner wrote:
 tamouse mailing lists tamouse.li...@gmail.com wrote in message
 news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I
 know
 if I want to modify $_SERVER myself?

 Once your script starts the superglobals are no different to any other
 variables, except that they're in scope at all times.

 That's probably the reason why they are named SuperGlobals. :-)

 But to be more descriptive, these are simply globals that are predefined
 by php -- see:

 http://php.net/manual/en/language.variables.superglobals.php

 I believe, (please show me otherwise) there are no globals in PHP other
 than SuperGlobals.

 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)

 Just to be clear - you asked if it were true that there are no globals in
 PHP other than SuperGlobals:  Don't forget that anything that you declare as
 global in a script is a global for that instance of that script (and
 whatever includes, etc. that it calls during its run)

 That's correct, but to access those variables outside of their scope (such as 
 a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

 As such, there are no globals in PHP other than SuperGlobals. As I said, if 
 I'm wrong, please show me otherwise.

I guess I don't know what you mean by globals. I know what globals
are, but not globals.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Matijn Woudt
On Sat, Mar 10, 2012 at 9:47 PM, tamouse mailing lists
tamouse.li...@gmail.com wrote:
 I'm just a bit baffled why this isn't a standard library function.

Good question, but I think the problem here is that there are tons of
these small functions, and you got to make a choice on what to
implement and what not. I can think of at least 20 other functions I'd
like to have integrated, but IMO PHP shouldn't be bloated with tons of
just 'useful' functions.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] looking for an array sorting function.. just not sure which one.. and how yet

2012-03-10 Thread Govinda
Hi Everyone

I am newbie enough with the terminology around PHP arrays that I am slow to 
wrap my head around what I know is in the docs (what i am reading)... but just 
can't identify yet.

I think it will be faster if someone can translate for me in terms of my 
question:

I make an array by building up its members form the results of a db call, like 
so:

foreach ($query-result() as $row) {
$arr_cTree[$row-cID] = array($row-cPcID, $row-cL, $row-cName, 
$row-cSeg, $row-cSort);
}

I have that array's members' values displaying on an HTML page fine by making 
recursive function calls to grab the children of each parent member found..  
but the order those array members are displayed on the page is not what I want 
(it seems to be displaying according to the order the rows are found in the 
db).  To remedy, I want to sort on the last value in the array which is the 
value of each array member.  (If I said that right.)   IOW,  I want to sort my 
$arr_cTree array by the decimal values stored in $row-cSort ($arr_cTree[[4]), 
before I then display on the page.

Can someone point me to the array sorting function you think is suited to this 
job.. and perhaps give me an example in pseudo code if that helps make it more 
clear in this case.

Thanks!
-Govinda
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: looking for an array sorting function.. just not sure which one.. and how yet

2012-03-10 Thread Shawn McKenzie
On 03/10/2012 06:42 PM, Govinda wrote:
 Hi Everyone
 
 I am newbie enough with the terminology around PHP arrays that I am slow to 
 wrap my head around what I know is in the docs (what i am reading)... but 
 just can't identify yet.
 
 I think it will be faster if someone can translate for me in terms of my 
 question:
 
 I make an array by building up its members form the results of a db call, 
 like so:
 
 foreach ($query-result() as $row) {
   $arr_cTree[$row-cID] = array($row-cPcID, $row-cL, $row-cName, 
 $row-cSeg, $row-cSort);
 }
 
 I have that array's members' values displaying on an HTML page fine by making 
 recursive function calls to grab the children of each parent member found..  
 but the order those array members are displayed on the page is not what I 
 want (it seems to be displaying according to the order the rows are found in 
 the db).  To remedy, I want to sort on the last value in the array which is 
 the value of each array member.  (If I said that right.)   IOW,  I want to 
 sort my $arr_cTree array by the decimal values stored in $row-cSort 
 ($arr_cTree[[4]), before I then display on the page.
 
 Can someone point me to the array sorting function you think is suited to 
 this job.. and perhaps give me an example in pseudo code if that helps make 
 it more clear in this case.
 
 Thanks!
 -Govinda

The best option is to sort it in the query.  But if for whatever reason
you sort it in the query for use one way and then need it sorted
differently later, then most likely execute another query with the new
sorting.  If having tried that, and that's not what works, then use
array_multisort().  Pay attention to example #3 on php.net as this is
what you want.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: looking for an array sorting function.. just not sure which one..and how yet

2012-03-10 Thread Shawn McKenzie
On 03/10/2012 07:01 PM, Shawn McKenzie wrote:
 foreach ($query-result() as $row) {
  $arr_cTree[$row-cID] = array($row-cPcID, $row-cL, $row-cName, 
 $row-cSeg, $row-cSort);
 }

Actually, you may construct your array as follows to make sorting with
ksort():

foreach ($query-result() as $row) {
$arr_cTree[$row-cSort] = array[$row-cID, $row-cPcID, $row-cL,
$row-cName, $row-cSeg, $row-cSort);
}


However you do it, look at constructing your array the way you need it
to easily sort, display etc.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: looking for an array sorting function.. just not sure which one.. and how yet

2012-03-10 Thread Govinda
 The best option is to sort it in the query.

yes, of course!, that makes sense..  I feel silly not thinking of that in the 
first place.
Now I do not need to sort the array with PHP..  but glad you mentioned 
array_multisort() as well.. so I could make a mental note of that function.

Thanks to Stephen too for your reply.  I appreciate the points you made..  and 
why, I believe.  (Even if I am not heeding them all just now)

Thanks guys!
-Govinda
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function mktime() documentation question

2012-03-10 Thread Tedd Sperling
On Mar 10, 2012, at 12:20 PM, Maciek Sokolewicz wrote:

 function getAmountOfDaysInAMonth($month, $year) {
   $days = array(31, (($year%4==0 and ($year%100  0 or $year%400==0)) ? 29 : 
 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   return $days[$month+1];
 }

I like that -- here's a small variation.

function numberDaysMonth($month, $year)
{
// Leap year is definded as a year that is evenly divisible by four
// AND (year NOT evenly divisible by 100 OR year IS evenly divisible by 
400) 

$feb = ($year%4 == 0  ($year%100 != 0 || $year%400 == 0) ) ? 29 : 28;
$days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
return $days[$month];
}

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-10 Thread Tedd Sperling
On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote:
 On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 That's correct, but to access those variables outside of their scope (such 
 as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].
 
 As such, there are no globals in PHP other than SuperGlobals. As I said, 
 if I'm wrong, please show me otherwise.
 
 I guess I don't know what you mean by globals. I know what globals
 are, but not globals.

I don't understand your question. I know what questions are, but not your 
question. :-)

Cheers,

tedd


_
tedd.sperl...@gmail.com
http://sperling.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php