Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:获取数组中的特定数据_Php_Arrays_Angularjs - Fatal编程技术网

PHP:获取数组中的特定数据

PHP:获取数组中的特定数据,php,arrays,angularjs,Php,Arrays,Angularjs,我无法获取数组的值。请帮帮我。我正在使用angularjs和php slim框架 这是我用PHP编写的代码: function testArray(){ $app = Slim::getInstance(); $app->response()->header("Content-Type", "application/json"); $post = json_decode($app->request()->getBody()); $data = get_object_

我无法获取数组的值。请帮帮我。我正在使用angularjs和php slim框架

这是我用PHP编写的代码:

function testArray(){
$app = Slim::getInstance();   
$app->response()->header("Content-Type", "application/json");
$post = json_decode($app->request()->getBody());
$data = get_object_vars($post);


echo json_encode(array_values($data['name']));}
这是我在控制器和工厂中的代码:

app.controller('fooCtrl', ['$scope', 'adminFactory', function($scope, adminFactory) {
$scope.arr = [{name:"rence"}, {name:"asd"}, {name:"qwe"}, {name:"qwe"}]; //your array
adminFactory.sendData($scope.arr).then(function(data) {
    console.log(data);
});}]);


adminFactory.sendData = function(arr) {
    return $http({
        withCredentials: false,
        method: 'post',
        url: urlBase + '/test',
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        data: {'arr': arr}
    });
};

我从php得到一个错误。500(内部服务器错误)。谢谢大家!

看起来您在服务器上需要json,但您添加了
表单urlencoded

$http
中删除
标题


此外,您还必须自己序列化数据以发送表单编码的

什么是
$data
包含的内容。我使用json_decode方法post来包含来自factory和controller$scope.arr的值仍然不起作用。不知道在这行中要做什么:$mynames=array_values($data['name'])。。我的线路对吗?我将序列化数组中的对象。对不起,我是PHP的新手。谢谢你的回答。