我使用的是angularJS控制器這樣PHP數組JSON
app.controller('customersCtrl', function($scope, $http) {
$scope.element = function(num){
var element_id = num;//num;
$http.get("customers.php",{params:{"id":element_id}}).then(function (response) {
$scope.myData = response.data;
}
,function errorCallback(response){
$scope.e=response.statustext;
console.log(e);
});
};
});
這是我的PHP陣列
$id = $_GET[id];
$customer_array = array();
$customer1 = array(
'name' => 'LoneStar',
'city' => 'Houston'
);
$customer_array[] = $customer1;
$customer2 = array(
'name' => 'SNHU',
'city' => 'Manchester'
);
$customer_array[] = $customer2;
$customer3 = array(
'name' => "Regis",
'city' => "Boulder"
);
客戶1陣列,我怎麼能只返回的只是城市名那一個元素。
你爲什麼要使用許多陣列,而不是使用一個單一的陣列,並嘗試應用過濾條件並返回該對象單獨 – Aravind
回聲json_encode($ customer_array);並得到迴應 – JYoThI
echo $ customer_array [0] ['city']; – JYoThI