I have the following language files:
main.php
<?php
$lang = array(
'blogName' => 'Blog Name',
'home' => 'Home',
'contact' => 'Contact'
);
?>
register.php
<?php
$regLang = array(
'register' => 'Register'
'name' => 'Name'
'email' => 'email'
'password' => 'Password'
);
$lang = array_merge($regLang, $lang);
?>
After $regLang and $lang have been merged, does $lang and $regLang point to the same elements in memory?
For example, does $regLang[‘name’] and $lang[‘name’] point to the same place in the server’s RAM?
Cups
July 9, 2011, 4:28pm
2
$lang1 = array(
'blogName' => 'Blog Name',
'home' => 'Home',
'contact' => 'Contact'
);
$lang2 = array(
'register' => 'Register' ,
'name' => 'MyName' ,
'email' => 'email' ,
'password' => 'Password'
);
$lang3 = array_merge($lang2, $lang1);
echo $lang3['name'] . ' / ' . $lang2['name'] .'<br >';
// MyName / MyName
// alter the copy **
$lang3['name'] = 'YourName';
echo $lang3['name'] . ' / ' . $lang2['name'] ;
// YourName / MyName
Nope, it made a copy, and works on that copy only.
Alter that to $lang2 and you will see the inverse.
Edit:
Why, do you want them to stay in sync?
Ok, so it would be best to use unset($regLang) after the merge if I don’t need it anymore or just wait till the end of the script?
Cups
July 9, 2011, 8:18pm
4
Good point I guess, if you have 1000 people hit your server for that fleeting instant for the exact same time, then I’d say you have a point in worrying.
Otherwise forget about it, and let PHP clean up after you - because that is one of the main reasons we use it.