我使用的是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