Sorting Object Array in Symfony on the basis of date & time

Viewed 2419

//Suppose Entity Notes has property 'creationdate' & 'getCreationDate()' method to access.

  DefaultController extends Controller {
         public function indexAction(){
           $em = $this->getDoctrine()->getManager();
           $repository = $em->getRepository('Bundle:Notes');
           $notes = $repository->findBy(array('userid' => $userId);
           //Now I want to sort the notes array as per creation date using usort
           usort($notes, array($this,"cmp"));
        }
     function cmp($a, $b) {
       return strtotime($a->getCreationDate()) > strtotime($b->getCreationDate())? -1:1;
     }
}
1 Answers
Related