Re: Array mysteries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




----- Original Message ----- From: "Otto Wyss" <otto.wyss@xxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Sunday, March 11, 2007 11:14 AM
Subject: Re:  Array mysteries


Steve Edberg wrote:
At 9:51 AM +0100 3/11/07, Otto Wyss wrote:

  function convert_from_weekday ($weekday) {
    return $wdays[$weekday];
  }

If the above is your exact code, then the problem is one of scope; move the $wdays declaration inside your convert_from_weekday() function.

I'm more used to C++ than PHP, with "global $wdays;" it works.


Unless you are using the array elsewhere, it might be a good idea to put it inside the function so as to not polute the global namespace with variable names that have no need to be there. In large applications, there is a non-trivial chance that someone else might use a variable by the same name and ruin your translation table. It will be slightly slower, though.


As for the localization functions, you might see their effect in:

http://www.satyam.com.ar/int/setlocale/index.php?locale=de_DE&submit=Aceptar

the input box allows you to enter different locales, the previous URL already has German selected.

Satyam

However, you may want to investigate the formatting functions of date():

http://php.he.net/manual/en/function.date.php

Date should return names using the native locale; if you want to return date strings for other locales/languages, use setlocale() -

http://php.he.net/manual/en/function.setlocale.php


Thanks, I'll keep this in mind.

O. Wyss

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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.8/717 - Release Date: 10/03/2007 14:25



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux