Php 从关联数组中删除元素

Php 从关联数组中删除元素,php,associative-array,Php,Associative Array,描述如何删除具有Unset的关联数组的元素,即Unset$array['key1'] 我有这个阵列: Array ( [queryLocator] => [done] => 1 [records] => Array ( [0] => stdClass Object ( [Id] => [CreatedDate] => 2016-08-28T14:

描述如何删除具有Unset的关联数组的元素,即Unset$array['key1']

我有这个阵列:

Array
(
[queryLocator] => 
[done] => 1
[records] => Array
    (
        [0] => stdClass Object
            (
                [Id] => 
                [CreatedDate] => 2016-08-28T14:43:45.000Z
                [Leader__c] => GF
                [Location__c] => Postbridge
                [Service_Date__c] => 2016-09-03
                [Service_Time__c] => 14:30
                [Service_Type__c] => Baptism
            )



    )

[size] => 42
[pointer] => 0
[QueryResultsf] => SforceEnterpriseClient Object
    (
        [sforce:protected] => SoapClient Object
            (
                [trace] => 1
                [compression] => 32
                [_encoding] => utf-8
                [_features] => 1
                [_user_agent] => salesforce-toolkit-php/20.0
                [_soap_version] => 1
                [sdl] => Resource id #8                 
        [packageVersionHeader:protected] => 
        [client_id:protected] => 
    )

我要删除键[queryLocator],将键[done]替换为[total],将键[records]替换为[rows],并删除所有后续键,即[size]、[pointer]等

使用unset,即unset$array['queryLocator'];没有效果


我做错了什么?谢谢。

以下是实现我想要的功能的代码—从Sales Force查询中获取输出,并按照EasyUI datagrid的要求对其进行格式化

 //--Get the Sales Force Data
 $response = $mySforceConnection->query($query);

//--Encode and decode - for some reason 
$data = json_encode((array)$response);
$x = json_decode($data,true);

//--Empty Array
$q = array();


//--Add array element for number records 
$q['total'] = $numRecs;
//--Copy the array element from original query with data
$q['rows'] = $x['records'];

//--JSON Encode the new array
$y = json_encode($q);

//--Return the array to Ajax call
echo ($y);
下面是一段经过验证的JSON

 {  
 "total":193,
 "rows":[  
  {  
     "Id":null,
     "CreatedDate":"2016-08-28T14:43:45.000Z",
     "Leader__c":"GF",
     "Location__c":"Postbridge",
     "Service_Date__c":"2016-09-03",
     "Service_Time__c":"14:30",
     "Service_Type__c":"Baptism"
  },
  {  
     "Id":null,
     "CreatedDate":"2016-08-17T20:43:10.000Z",
     "Leader__c":"GF",
     "Location__c":"Ashburton",
     "Service_Date__c":"2016-09-04",
     "Service_Time__c":"08:00",
     "Service_Type__c":"HC 2"
  },
  {  
     "Id":null,
     "CreatedDate":"2016-08-17T20:43:10.000Z",
     "Leader__c":"GF",
     "Location__c":"Bickington",
     "Service_Date__c":"2016-09-04",
     "Service_Time__c":"09:00",
     "Service_Type__c":"HC 2"
  },
  {  
     "Id":null,
     "CreatedDate":"2016-08-17T20:43:10.000Z",
     "Leader__c":"MC",
     "Location__c":"Holne",
     "Service_Date__c":"2016-09-04",
     "Service_Time__c":"10:30",
     "Service_Type__c":"HC 1"
  },

我对数组操作有点费劲,但它确实有效。欢迎任何代码改进建议

只需使用未设置的$array_值['queryLocator']$数组_值未定义。你是说$结果=数组$响应;未设置数组_值$result['queryLocator'];这会产生致命错误:无法在未设置行的写入上下文中使用函数返回值。$array_值应替换为数组变量名@peterSorry,但$result=array$response;未设置$result['queryLocator'];不执行任何操作-没有错误,但queryLocator密钥仍然存在@佐提