Find us on facebook

Aug 18, 2014

Get Unique values from an array

public function actionGetLunchCategory() {

$this -> layout = false;
header('Content-type: application/json');

$id = $_POST['id'];
$LunchMenus = MenuDiningtypes::model() -> findAll(array("condition" => "diningtypes_type_id =  $id"));

$LunchCategories = array();
foreach ($LunchMenus as $LunchMenu) {
$menu_id=$LunchMenu->menu_id;
$Menu = Menu::model() -> find(array("condition" => "id = $menu_id "));

$mainmenu_id=$Menu -> main_menu;

$MainMenu = MainMenu::model() -> find(array("condition" => "id = $mainmenu_id "));

$path = "/" . $MainMenu -> id . "/" . $MainMenu -> image;
$return_array = array('id' => $MainMenu -> id, 'name' => $MainMenu -> name, 'image' => $path, );
array_push($LunchCategories, $return_array);
}
$LunchCategories = array_unique($LunchCategories,SORT_REGULAR);
echo CJSON::encode($LunchCategories);
Yii::app() -> end();

}

No comments:

Post a Comment