memcache list keys and values in PHP

Memcache is free and powerful cache system which is a must for large projects. There isnt much help on internet in retrieving keys and values in a php project. Memcache stores values in different slabs. here is how you can get the keys and values of memcache.

 $list = array(); 
        $allSlabs = $memcache->getExtendedStats('slabs'); 
        $items = $memcache->getExtendedStats('items'); 
        foreach($allSlabs as $server => $slabs) { 
            foreach($slabs AS $slabId => $slabMeta) { 
               $cdump = $memcache->getExtendedStats('cachedump',(int)$slabId); 
                foreach($cdump AS $keys => $arrVal) { 
                    foreach($arrVal AS $k => $v) {                    
                        echo $k .'<br>'; 
                    } 
               } 
            } 
        }