I am doing some sql caching of certain queries. I’m using CakePHP so the query conditions are in an array thus:
array (
0 =>
array (
0 => 'Tutorial.id IN ( SELECT tutorial_id FROM classifications WHERE classifications.product_id = 1 ) ',
),
1 =>
array (
'Tutorial.status_id ' =>
array (
0 => 4,
1 => 7,
),
),
'OR' =>
array (
'Tutorial.user_id' => '40',
),
);
I’m mostly looking for the product_id, but there are some other possible conditions, so I wanted to reduce the array to a checksum and append it to the name of the cache file. This way I’d have tutorials_by_classification-413a86af or something, and I wouldn’t have to pick thru the array.
I’ve seen the function to implode mutli-d arrays on php.net in the comments, but I’m wondering if there’s a simpler way to achieve my goal.
How about
serializeandmd5?serializecreates a string representation of your array;md5creates a hash of it.Example: