【发布时间】:2020-12-06 14:55:33
【问题描述】:
我在使用以下 PHP 版本的应用程序中遇到以下错误: 如果我可以在 PHP 版本上更改某些内容,您能否帮我说一下,它会起作用。我试图找到有这个错误的东西,但在他们的特定代码上。不得不提的是,比起 PHP 开发者,我更像是一名具备 Linux 技能的应用程序管理员。
PHP 7.4.9 (cli) (built: Aug 4 2020 08:28:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
遇到 PHP 错误 严重性:警告 消息:sizeof():参数必须是数组或实现了 Countable 的对象 文件名:库/MY_HTML.php 行号:89
代码:
/**
*
* @param string $name - select element "name" atribute
* @param (array or stdClass) $option_array - option array with value and text
* @param int $selectedIndex - which index is selected bby default
* @param string $spec - selectbox specifications (html code, example: "id=\"select\" style=\"background-color: #FFF;\"")
* @param string $selectedValue - option with this "value" is selected
* @return string - select element to be printed
*/
function createHolidaySelectBox($name, $option_array,
$selectedIndex = 0, $spec = "", $selectedValue = NULL) {
$select_box = "<select name=\"$name\" " . $spec . ">";
$i = 0;
foreach ($option_array as $v) {
if ($v->isActive()) {
if (sizeof($v) < 2) {
$val = array_keys($option_array, $v);
$opt = array($val[0], $v);
} else {
$opt = $v;
}
$select_box.="<option value=\"" . $opt[0] . "\"" . (($selectedValue == NULL) ? ($i == $selectedIndex ? " selected" : "") :
(($opt[0] == $selectedValue) ? " selected" : "")) . ">" . $opt[1] . "</option>";
$i++;
}
}
$select_box.="</select>";
return $select_box;
}
}
【问题讨论】:
-
$v是一个值,而不是一个数组。 -
如果我降级 php 版本会将 $v 视为不显示此警告的值?
-
您尝试过什么调试问题?你想达到什么目标?
标签: php