0

我有这个:

$custom = var_export('return ' . self::$push_action['custom']($data), true);

这将调用此方法:

protected static function match($data) {
    $match = service::$db->select('matches', 'match_id', array('user_id' => $data['user_id'], 'opponent_id' => $data['opponent_id']), 'ORDER BY match_id DESC LIMIT 1');
    return array('match_id' => $match[0]['match_id']);
}

但我收到此错误:

Notice:  Array to string conversion in....

如何从match($data)方法中正确返回数组?

$custom我需要用返回的数组填充变量。

谢谢你的帮助

4

2 回答 2

0

基本上你不能var_export用来返回一个数组(var_export DOC

输出或返回变量的可解析字符串表示

于 2013-08-02T14:01:49.337 回答
0

根据描述:

$custom = self::$push_action['custom']($data);

如果要将数据导出到文件并稍后将其读取到 $custom 比:

写入文件“foo.php”:

$fileContent = 'return ' . var_export(self::$push_action['custom']($data), true) . ';';
file_put_contents('foo.php', $fileContent);

从文件“foo.php”读取到 $custom:

$custom = include 'foo.php"
于 2016-11-28T15:18:58.577 回答