【发布时间】:2017-04-22 05:28:05
【问题描述】:
我正在使用这样的 angularJS 控制器
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 数组,我怎样才能只返回那个元素的城市名称。
【问题讨论】:
-
为什么要使用多个数组而不是使用单个数组并尝试应用过滤条件并单独返回该对象
-
回显 json_encode($customer_array);并得到响应
-
echo $customer_array[0]['city'];