Jump to content

Recommended Posts

hi guys,

i have the following function

 


//getting all providers
function getAllProviders($tarifarray) {

$i = 0;
$provider_array = array ();
foreach ( $tarifarray ['tarifarray'] as $key => $val ) {
	$energyprovider = $val ['versorgerName'];
	$providerid = $i;
	$temparray = array ($energyprovider => $providerid );
	$provider_array = array_merge ( ( array ) $provider_array, ( array ) $temparray );
	$i ++;
}

return $provider_array;

}

 

and it is recalled in many cases with the same result....how can i configure it so it caches the return value? unless it changes.

 

 

Link to comment
https://forums.phpfreaks.com/topic/193756-caching-a-functions-array-result/
Share on other sites

If the many calls you describe, are all on the same page, then you can set this up as a class, have the array as a class variable, then when instantiating you set up the array, then you would have a function to get the array when necessary.

 

The global storage is also an option as has been suggested.

 

If the resultant array is required on many pages, then storing it in the session would be an answer for you

thanks guys.

 

you can store the result on global variable or something. You can't actually do what you want, cause in that case you need to check in the result is the same

 

well if i have to check if it is same each time, then i am doing the calculation again which consumes resources...or not?

thanks guys.

 

you can store the result on global variable or something. You can't actually do what you want, cause in that case you need to check in the result is the same

 

well if i have to check if it is same each time, then i am doing the calculation again which consumes resources...or not?

 

Yeah. Unless you put trigger or something on function that changes values, so it has to calculate only when someone changes values. I am not sure if that is possible in you case thought.

 

Goat

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.