我有这个PHP代码片段:的foreach在一个变量
<?php
$imageresults = get_image_big($string);
foreach ($imageresults as $hasil) { ?>
<img src="<?php echo $hasil['media']; ?>" />
<?php } ?>
我想输出的结果在一个变量,但它不工作... 我想:
<?php
function bigimgx() {
$imageresults = get_image_big($string);
foreach ($imageresults as $hasil) {
echo "<img src=\"" . $hasil['media'] . "\" />";
};
};
$result = bigimgx();
?>
任何想法,我的错误可能是?谢谢。
你必须'从功能return'一个值,而不是'echo'它。查看PHP手册以了解有关函数的更多信息:http://php.net/manual/en/language.functions.php。 –