PHP - 在对象中获取数组

时间:2016-07-12 15:23:30

标签: php arrays object foreach

我将以下对象显示为Json对象:

Vtiger_RequestObject([
  valuemap: Vtiger_Request: private
]=>Array([
  __vtrftk
]=>sid: 172e53bdd05f5ef334859018d08043fb563b23b9,
1468335904[
  picklistDependency
]=>[

][
  module
]=>Calendar[
  action
]=>SaveAjax[
  defaultCallDuration
]=>5[
  defaultOtherEventDuration
]=>5[
  userChangedEndDateTime
]=>0[
  subject
]=>jhala12345tst[
  assigned_user_id
]=>1[
  date_start
]=>12-07-2016[
  time_start
]=>05: 05PM[
  due_date
]=>12-07-2016[
  time_end
]=>05: 10PM[
  eventstatus
]=>Dovoláno[
  activitytype
]=>Call[
  cf_1181
]=>Odchozí[
  followup_date_start
]=>[
  followup_time_start
]=>[
  popupReferenceModule
]=>Potentials[
  contact_id
]=>[
  contact_id_display
]=>[
  relatedContactInfo
]=>[
  parent_id
]=>[
  parent_id_display
]=>)[
  rawvaluemap: Vtiger_Request: private
]=>Array([
  __vtrftk
]=>sid: 172e53bdd05f5ef334859018d08043fb563b23b9,
1468335904[
  picklistDependency
]=>[

][
  module
]=>Calendar[
  action
]=>SaveAjax[
  defaultCallDuration
]=>5[
  defaultOtherEventDuration
]=>5[
  userChangedEndDateTime
]=>0[
  subject
]=>jhala12345tst[
  assigned_user_id
]=>1[
  date_start
]=>12-07-2016[
  time_start
]=>05: 05PM[
  due_date
]=>12-07-2016[
  time_end
]=>05: 10PM[
  eventstatus
]=>Dovoláno[
  activitytype
]=>Call[
  cf_1181
]=>Odchozí[
  followup_date_start
]=>[
  followup_time_start
]=>[
  popupReferenceModule
]=>Potentials[
  contact_id
]=>[
  contact_id_display
]=>[
  relatedContactInfo
]=>[
  parent_id
]=>[
  parent_id_display
]=>)[
  defaultmap: Vtiger_Request: private
]=>Array())

我希望使用foreach探索数组,并使用array_key_exists()搜索[cf_1181] => Odchozí。可能吗?

我怎么能意识到这一点?

2 个答案:

答案 0 :(得分:0)

您无法更改创建此对象的类吗? 简单方法 - 将getter添加到类中,但如果无法更改类,则可以使用Reflection api。 但它很慢!

$reflectionClass = new ReflectionClass('Vtiger_Request');
$reflectionProperty = $reflectionClass->getProperty('valuemap');
$reflectionProperty->setAccessible(true);
var_dump($reflectionProperty->getValue($obj)); // TODO $obj - is you object

答案 1 :(得分:0)

仅适用于vtiger,仅适用于版本7.x
您可以通过Vtiger_Request方法获取所有数据:

getall()

get($key, $defvalue = '') 

类似

$data_all_data = $request->getAll();

 $data_by_key = $request->get($key);