2015-06-20 72 views
-1

我需要在PHP中創建它,並用逗號分隔它們,在mysql查詢中。生成PHP到Javascript

{ 
    title : 'Property', 
    image : '1-1-thmb.png', 
    type : 'For Sale', 
    price : '$price', 
    address : '$address', 
    bedrooms : '$bedrooms', 
    bathrooms : '$maxguests', 
    area : '$area', 
    position : { 
     lat : 47, 
     lng : 19 
    }, 
    markerIcon : 'marker-green.png' 
} 

你能幫我嗎這可能嗎?

由於提前,

我曾嘗試這樣的:

$map_flats = array(
    title => 'Property', 
    image => '1-1-thmb.png', 
    type => 'For Sale', 
    price => $price, 
    address => $address, 
    bedrooms => $bedrooms, 
    bathrooms => $maxguests, 
    area => $area, 
     lat => $lat, 
     lng => $lng, 
     markerIcon => 'marker-green.png' 
     ); 

蒂博爾

回答

2

這是一個JSON數組語法。您可以在PHP documentation中瞭解JSON符號,或者試試這個:

$json = json_encode($obj); // Encodes object properties/array to JSON 
$obj = json_decode($json); // Decodes JSON to stdClass object 
$arr = json_decode($json, true); // Decodes JSON as array