I’m implementing memcached on a site and I’m caching the results of a specific query, which is working great, but I am having problems putting together the code to set the variables I need to make the cache usable.
My array is as follows, which contains two groups of data:
Array ( [0] => Array ( [0] => 9126 [id] => 9126 [1] => Oh penguin, you so silly. [title] => Oh penguin, you so silly. [2] => November-01-2011-00-14-09-ScreenShot20111031at9.jpg [path] => November-01-2011-00-14-09-ScreenShot20111031at9.jpg ) [1] => Array ( [0] => 9131 [id] => 9131 [1] => Reasons you die... [title] => Reasons you die... [2] => November-01-2011-00-17-04-ScreenShot20111031at8.jpg [path] => November-01-2011-00-17-04-ScreenShot20111031at8.jpg ) )
I can set them manually, and call them like this:
$id = $clean[0][0];
$title = $clean[0][1];
$path = $clean[0][2];
But I am having problems writing a WHILE loop to go through and set the variables dynamically. I also tried a FOR EACH statement to no avail:
for each($clean as $image){
$id = $image->id;
$path = $image->path;
$title = $image->title;
echo "THIS IS YOUR FREAKING ID $id THIS IS YOUR TITLE $title THIS IS YOUR PATH $path";
}
Any insight?
Edit:
Solution was to not call them as objects, as pointed out, change to reference them like this:
$id = $image["id"];
$path = $image["path"];
$title = $image["title"];
Cheers.
You could just serialize the entire array before saving in cache, then unserialize when you retrieve from cache. Then just reference the values as you indicated.