格式化xmlrpcmsg数组

时间:2014-10-07 16:41:01

标签: php arrays xml-rpc

我有以下数组

  Array ( [value] => Array ( [mf_account] => xxxxx [mf_username] => xxxx [mf_password] => xxxx [as_user_id-int] => e [page-int] => d [page_size-int] => x [get_campaign] => Submit [form_build_id] => form-w1vXG5j2hEeKjKYGomZjuwxWlXqbrGg5tG4ph81J3Xk [form_token] => 9onu89rRyvEWWVtSJpAUw4Ko81sitmo9BpbqtoVD110 [form_id] => messagefocus_settings_all_campaign ) )

我需要格式化这个数组,以便它适合xmlrpc_client

如果我像下面那样硬编码数组

 $msg = new xmlrpcmsg(
  "campaign.all",
  array(
    new xmlrpcval(
      array(
        "as_user_id"=> new xmlrpcval('122', "int"),
        "page"=> new xmlrpcval('33', "int"),
        "page_size"=> new xmlrpcval('23', "int"),
      ),"struct"
    )
  )
);

不幸的是,我有太多的表单来处理所有的硬编码处理程序,所以我真的希望有一个函数可以循环一个尚未格式化的数组并根据需要解析这些值。

到目前为止,我已经尝试了这个,但我只是收到错误。

  //Please ignore all parts of the if statement except the final else
  $temp = new xmlrpcmsg();
  foreach ($data as $key => $value) {
    if($key == 'get_campaign'){
      break;
    }elseif ($key == 'mf_account' || $key == 'mf_username' || $key == 'mf_password') {
      $credentials[$key] = $value; 
    }else{
      //this is where my problems occurs
      $keyValues = split('-', $key);
      $temp[$keyValues[0]] => new xmlrpcval($value, $keyValues[1]);
    }
  }

对我来说调试这个很麻烦,因为我必须在drupal中开发它并且表单是通过ajax处理的,这意味着我回来的唯一错误是

  An AJAX HTTP error occurred.
  HTTP Result Code: 500
  Debugging information follows.
  Path: /system/ajax
  StatusText: Internal Server Error
  ResponseText: 

1 个答案:

答案 0 :(得分:0)

通过删除$ temp的第一个声明,错误消失了。

 $temp = new xmlrpcmsg();

然后我只是保持循环

  //$temp = new xmlrpcmsg();
  foreach ($data as $key => $value) {
    if($key == 'get_campaign'){
      break;
  }elseif ($key == 'mf_account' || $key == 'mf_username' || $key == 'mf_password') {
    $credentials[$key] = $value; 
  }else{
    //this is where my problems occurs
    $keyValues = split('-', $key);
    $temp[$keyValues[0]] => new xmlrpcval($value, $keyValues[1]);
  }
}     

然后我格式化了这样的消息

 $temp = new xmlrpcmsg("campaign.all", array( new xmlrpcval($temp), "struct"));