Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

populating associative array from a function

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

populating associative array from a function

Postby neverbend007 » Tue Mar 25, 2014 8:35 am

Hi

I am trying to construct an associative array by using a function to populate some of the values as follows.

$month = array(1 => translate('January'), 2 => translate('February'),.......................12 => translate('December'))

translate() is a function I am using to translate English words and names to French. I have used it everywhere else and it has worked fine. My question is, is it not possible to call a function in this way to populate part of an associative array?
neverbend007
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Mar 25, 2014 8:28 am

Re: populating associative array from a function

Postby seandisanti » Sat Mar 29, 2014 1:04 am

Your challenge is coming from the scope of the variable containing the array. If you're declaring it outside of the function, make sure you use global $variableName; in the function to specify that you're going to be referencing th global variable rather than one in local scope. if the variable is defined locally to the function (inside the function) then you'd have to return it to the calling context in order to make the results available
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron