在此测试页面https://wintoweb.com/sandbox/question_2.php 上,访问者可以在数据库中进行搜索并根据需要勾选任意数量的复选框。当单击按钮 [接受...] 时,我希望所有搜索的结果都显示在“到目前为止您的选择”下。现在,只显示最后一次搜索。我尝试使用全局数组来存储先前搜索的结果并在每次新搜索时增加它。这就是我有问题的地方。
在文件顶部我有:
<?php
global $all_authors;
array ($all_authors, '');
?>
在文件底部我有:
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
if(isset($_GET['search'])){
//echo 'Search</br>';
} elseif(isset($_GET['display_this'])) {
echo getNames();
}
function getNames() {
$rets = '';
if(isset($_GET['choices']) and !empty($_GET['choices'])){
foreach($_GET['choices'] as $selected){
$rets .= $selected.' -- ';
}
//array_push($all_authors, $rets); // This is the problem
//print_r($allAuthors); // this too
echo '</br><b>Your selections so far :</b></br>';
}
return $rets;
}
?>
预期:要列出所有先前搜索的结果 实际:由于 array_push() 问题,无法进行。参见函数 gatNames()
牧羊人nacy
SMILET