Hello, I am just curious if this is the most efficient way of assigning an array to another variable. Here is my situation. I have an object with a variable $currentlang. I have several files that contain the $lang variable with an array of different languages. my code: require_once('english.php'); this->currentlang = $lang; my main concern is I don't want two arrays holding the same data since the array can be very large. Thanks guys.
to "delete" or clear the memory from the old array simply assign "nothing" to it i.e. $array = ""; The main question is why do you need to assign an array to another variable, and then remove the original. It makes no sense?
I'm pretty sure that php5 only passes a reference to the original array. Basically: $array = array{1,2,3,4,5); $newArray = $array; //you only reference $array, you don't actually create another array PHP: If you're using php4 you can reference the array by using &. $array = array{1,2,3,4,5); $newArray = &$array; PHP:
I want all my functions to go through tms_core class for ease of use and security reasons. I don't think there is a way to load the contents of english.php straight into $this->$currentlang without having to declare an array in the language files. I would prefer it that way or if there is a way to just use one variable. My Language file contains: <? $Lang = array( 'welcome' => 'welcome', 'video' => 'video', );?> Code (markup): My class file cotains: class tms_core extends Smarty { //Array of current language var $currentlang; function tms_core(){ require_once("english.php"); // this is dynamic. it could be french.php. $this->$currentlang = $lang; } } Code (markup):
<? echo sprintf('%s<br/>', memory_get_usage(true)); $array = array(); $i = 100000;while($i > 0){$array[]=$i;$i--;} echo sprintf('$array = array(); $i = 100000;while($i > 0){$array[]=$i;$i--;}: %s<br/>', memory_get_usage(true)); $newArray = $array; echo sprintf('$newArray = $array;: %s<br/>', memory_get_usage(true)); $byref = &$array; echo sprintf('$byref = &$array; %s<br/>', memory_get_usage(true)); echo phpversion(); ?> Code (markup): 262144 $array = array(); $i = 100000;while($i > 0){$array[]=$i;$i--;}: [U]7602176[/U] $newArray = $array;: [U]7602176[/U] $byref = &$array; [U]12320768[/U] 5.2.3 Code (markup):