Check if a value exists in an array and store the associative array in an array ..?

Discussion in 'PHP' started by 123GoToAndPlay, Mar 30, 2011.

  1. #1
    Hi,

    I am a bit stuck with the following function. The goal is:
    - Loop through an array which holds all products
    - Divide products based on luxury vs no_luxury
    - Another layout for available products, i have a seperate function for available products, it returns an associative array.

    The main problem i have i can't parse the price value out of the availableProducts array.
    Here's my simplified php code
    
    <?php
    $staticData = getStaticData();
    $availableProducts = getAvailableProducts();
    
    function getAllProductTypes($availableProducts, $staticData) {
        
        $allProductsTypes = array();
        $luxury = array();
        $no_luxury = array();
    	
        $no_luxury_products = array('CALL','DODO','PKK','YTK','TK');
        //available products other layout with price and buy now button
        $available = array();
    	//temp array for available products
        foreach($availableProducts as $value ){
            $available[] = $value['productType'];
    		//HOW TO STORE an assoc array 
        }
    	//get all products without price 
        $allProducts = getAllProducts();
         
    	 foreach ($allProducts as $value) {
            if(in_array($value["productType"], $no_luxury_products)){
                $no_luxury[] = $value;
            } else {
                $luxury[] = $value;
            }
        }
    	//div no luxury
        
    	$return = '<div id="no_luxury" style="background-color:#0099FF;">';
    
        foreach ($no_luxury as $value) {
    		//and productType is not availabe
            if(!in_array($value['RoomType'],$available)){ 
            		$return .= 'test'.$value['productType'].': '.$value['productDescr'];
            }//end not available
            else {//products ara available we have a price
    				//problem i need to get the $value from the $availableProducts assoc array
                	$return .= 'Price from $availableProducts assoc Array '.$value['productPrice'].': '.$value['productDescr'].' by '.$staticData['owner'];
            }
        }
        $return .= '</div>';
    	//end no luxury
    
    	//div luxury
        $return .= '<div id="luxury" >';
        foreach ($luxury as $value) {
    		//and productType is not availabe
             if(!in_array($value['RoomType'],$available)){ 
           			$return .= 'test'.$value['productType'].': '.$value['productDescr'];
             }//end not available
             else {//products ara available we have a price
    		 	//problem i need to get the $value from the $availableProducts assoc array
                  $return .= 'Price from $availableProducts assoc Array '.$value['productPrice'].': '.$value['productDescr'].' by '.$staticData['owner'];
             }
        }
    
        $return .= '</div>';
        return $return;
    }
    
    PHP:
    Any suggestions?
     
    123GoToAndPlay, Mar 30, 2011 IP