gpt4 book ai didi

php - ob_get_clean,只工作两次

转载 作者:行者123 更新时间:2023-12-05 08:14:43 26 4
gpt4 key购买 nike

采用这个简单的脚本:

ob_start();
$text = array();

echo 'first text';
$text[] = ob_get_clean();

echo 'second text';
$text[] = ob_get_clean();

echo 'third text';
$text[] = ob_get_clean();

echo 'fourth text';
$text[] = ob_get_clean();

print_r($text);

这个输出:

third textfourth textArray
(
[0] => first text
[1] => second text
[2] =>
[3] =>
)

但我希望:

Array
(
[0] => first text
[1] => second text
[2] => third text
[3] => fourth text
)

PHPFiddle

最佳答案

正确地执行此操作,您应该在 ob_get_clean() 之后执行 ob_start()

<?php
ob_start();
$text = array();

echo 'first text';
$text[] = ob_get_clean();
ob_start();

echo 'second text';
$text[] = ob_get_clean();

ob_start();

echo 'third text';
$text[] = ob_get_clean();

ob_start();

echo 'fourth text';
$text[] = ob_get_clean();

print_r($text);
?>

关于php - ob_get_clean,只工作两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17813832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com