[英]"TypeError: implode(): Argument #2 ($array) must be of type ?array, string given" in PHP 8
<div class="form-group col-md-8" id="my" style="display: none;">
<label>Choose Vpn Server</label>
<div class="row">
<?php
$sqlUrl4 = "SELECT * FROM vpn_networks";
$result4 = myQuery($sqlUrl4);
while ($row4 = myFetchArray($result4)) {
?>
<div class="col-sm-4 text-center">
<label>
<input type="checkbox" name="vpn_network[]" value="<?php echo $row4['id'];?>" id="iptv" />
<?php echo $row4['title'];?>
</label>
</div>
<?php
}
?>
</div>
</div>
$vpn1 =implode(',', $_POST['vpn_network']?? '');
Error:错误:
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must
be of type ?array, string given in
C:\xampp\htdocs\ideology\partnerprocess.php:22 Stack trace: #0
C:\xampp\htdocs\ideology\partnerprocess.php(22): implode(',', '') #1
{main} thrown in C:\xampp\htdocs\ideology\partnerprocess.php on line
22
$_POST['vpn_network']?? ''
$_POST['vpn_network']?? ''
means that the value can either be the array that you submitted or a string. $_POST['vpn_network']?? ''
表示该值可以是您提交的数组或字符串。 It would make more sense to have $_POST['vpn_network']?? []
拥有$_POST['vpn_network']?? []
$_POST['vpn_network']?? []
. $_POST['vpn_network']?? []
。
You really should not trust the values submitted in the form.您真的不应该相信表单中提交的值。 Check each of your assumptions.检查你的每一个假设。 If you expect an array than check if it is an array.如果您期望一个数组而不是检查它是否是一个数组。
$vpn_network = isset($_POST['vpn_network']) && is_array($_POST['vpn_network']) ? $_POST['vpn_network'] : [];
$vpn1 =implode(',', $vpn_network);
You could also use the filter extension
.您也可以使用filter extension
。 It offers a number of filters that can validate the data coming from forms.它提供了许多过滤器,可以验证来自 forms 的数据。
implode() function second parameter must be array. implode() function 第二个参数必须是数组。 Deprecated non array in second parameter.第二个参数中不推荐使用非数组。
please check for more details: https://www.php.net/manual/en/migration74.deprecated.php请查看更多详细信息: https://www.php.net/manual/en/migration74.deprecated.php
Legacy signature (deprecated as of PHP 7.4.0, removed as of PHP 8.0.0):遗留签名(从 PHP 7.4.0 开始弃用,从 PHP 8.0.0 开始删除):
implode(array $array, string $separator): string
User this instead:改用这个:
implode(string $separator, array $array): string
source: https://www.php.net/manual/en/function.implode.php来源: https://www.php.net/manual/en/function.implode.php
Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /var/www/html/pages/home.php:14 Stack trace: #0 /var/www/html/index.php(51): include() #1 {main} thrown in /var/www/html/pages/home.php on line 14致命错误:未捕获的 TypeError:array_key_exists():参数 #2 ($array) 必须是数组类型,null 在 /var/www/html/pages/home.php:14 堆栈跟踪:#0 /var/www/ html/index.php(51): include() #1 {main} 抛出 /var/www/html/pages/home.php 第 14 行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.