-5
我试图找出如何排列内部某个对象,但很难得到明确的答案。真的很头痛。我的程序运行如下:PHP:我们可以排列一个对象吗?
欲了解更多信息:我在底部附加了$ df和$ type的原始代码。
下面是代码:
$arr1 = array('uncle1','uncle2','uncle3','uncle4','uncle5');
$arr2 = array('aunt1','aunt2','aunt3','aunt4','aunt5');
$arr3 = array('child1','child2','child3','child4','child5');
$un = 'uncle1';
$au = 'aunt1';
$ch = 'child1';
switch ($type){
case 'family':
$family1 = ($df->createElement($un,$au,$ch);
//------- How I make an object base on many family at these arrays above, I try to foreach, but it can not run under function switch, It should has many objects like: $family1, $family2, $family3,.. with data from the array.
$df->sendFamily(array($family));
}
//---------it should be like: $df>sendFamily(array($family1,$family2,....)) but I can not array an object
这里$ DF的原始代码和$类型:
if (isset($_GET['msg']) && ! empty($_GET['msg']))
{
$df = new Chatfuel();
$type = strtolower($_GET['msg']);
//----- Begin an Chatfuel
class Chatfuel
{
protected $response = array();
public function __construct($debug = FALSE)
{
if ((! $debug) && (! isset($_SERVER['HTTP_USER_AGENT']) OR strpos($_SERVER['HTTP_USER_AGENT'], 'Apache-HttpAsyncClient') === FALSE)) {
exit;
}
}
public function __destruct()
{
if (count($this->response) > 0) {
try {
header('Content-Type: application/json');
echo json_encode(array('messages' => $this->response));
exit;
} catch (Exception $e) {
}
}
}
public function createElement($title, $image, $subTitle, $buttons)
{
if ($this->isURL($image) && is_array($buttons)) {
return array(
'title' => $title,
'image_url' => $image,
'subtitle' => $subTitle,
'buttons' => $buttons
);
}
return FALSE;
}
为什么不在类中返回一个返回相关对象数组的方法? –
感谢Ofir。当然,我将使用foreach从数组中获取每个数据。但我卡住了,因为我不能在函数createElement中使用循环:( – Axxx
)您需要修改$ df类,但是您可以。该类的代码是什么? –