【发布时间】:2014-09-29 11:45:28
【问题描述】:
只是想知道我们是否可以执行以下操作:
我想将函数中的 foreach 循环作为属性传递。
<?php
TestMethodForEach( foreach($_POST['activity'] as $activityID){ $activityID; } );
?>
如何在php中实现这个功能?
这是我的真实代码:
<?php
$accountServices->RL_ChangeInActivities(
new IhcStructRL_ChangeInActivities(
new IhcStructChangeActivity(
'00000000-0000-0000-0000-000000000000',
$accountID,
$_POST['serviceID'],
'1',
'IhcStructChangeActivity',
'teset,etsagad, asdfasd',
new IhcStructArrayOfAccountActivity(
new IhcStructAccountActivity(
'00000000-0000-0000-0000-000000000000',
'activityID 1',
$accountID,
'IhcStructAccountActivity',
'ActivityNumber'
)
)
)
)
);
?>
其实我想重复这个对象IhcStructArrayOfAccountActivity。
您将在此对象(新的 IhcStructAccountActivity)中看到(ActivityID 1),所以我有超过 5 个或可能更多的活动 ID,没关系。那么我怎样才能动态地重复这个对象,所以它应该看起来像
<?php
new IhcStructArrayOfAccountActivity(
new IhcStructAccountActivity(
'00000000-0000-0000-0000-000000000000',
'activityID 1',
$accountID,
'IhcStructAccountActivity',
'ActivityNumber'
)
)
new IhcStructArrayOfAccountActivity(
new IhcStructAccountActivity(
'00000000-0000-0000-0000-000000000000',
'activityID 2',
$accountID,
'IhcStructAccountActivity',
'ActivityNumber'
)
)
new IhcStructArrayOfAccountActivity(
new IhcStructAccountActivity(
'00000000-0000-0000-0000-000000000000',
'activityID 3',
$accountID,
'IhcStructAccountActivity',
'ActivityNumber'
)
)
?>
希望你现在明白了。
【问题讨论】:
-
您为什么要这样做?您要寻找的行为是什么?
-
您已经编写了代码,为什么不直接运行它并回答您自己的问题?
-
是的兄弟,我相信这没有任何意义,但有没有这样的方法?实际上我想在 xml 中重复该值。
-
做旧的 Reverse-a-roo 以获得相同的结果
-
我已经更新了代码,请看一下。