I have an array that gets queried each time a page is loaded, so I want to minimize the overhead and store the array into a session variable. The array file is 15kb so far. I still have to add about 300 words to each array sub key. So the file size might grow to anywhere from 100kb to 500kb. Just a guess.
The array is used to store the page data such as title, description and post content.
Here is the structure of the array:
11 main keys.
Within those main keys are sub keys anywhere from 1 to 20. Most have about 3 to 7.
each sub key has it's own array with title, description and post.
Title and description do not hold much, but post will hold approximately 300 words or less.
The values in the array will remain static.
Here's a sample of what it looks like with 2 main keys and 2 sub keys under each.
$pages = array(
'Administrator' => array(
'network-administrator' => array('title' => 'title info here', 'description' => 'description info here', 'post' => '<p>post info here - about 300 words.</p>'),
'database administrator' => array('title' => 'title info here', 'description' => 'description info here', 'post' => '<p>post info here - about 300 words.</p>'),
),
'Analyst' => array(
'business systems analyst' => array('title' => 'title info here', 'description' => 'description info here', 'post' => '<p>post info here - about 300 words.</p>'),
'data-analyst' => array('title' => 'title info here', 'description' => 'description info here', 'post' => '<p>post info here - about 300 words.</p>'),
),
);
My questions are three part.
1) Can I put this into a session variable and still be able to access the data from the session array the same way I'm accessing it directly from the array itself?
2) Is there any benefit to putting the array into a session to lessen the overhead of looping through the array on each page load?
This is how I access a value from the array
$content = $pages['Administrator']['network-administrator'];
$title = $content['title'];
$description = $content['description'];
$post = $content['post'];
3) Would I now access the array value using the same as above or writing it like this?
$pages = $_SESSION[$pages];
$content = $pages['Administrator']['network-administrator'];
$title = $content['title'];
$description = $content['description'];
$post = $content['post'];
Need some clarity, thanks for your help.