简体   繁体   English

“TypeError: implode(): Argument #2 ($array) must be of type?array, string given” in PHP 8

[英]"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.

相关问题 PHP 致命错误:未捕获的类型错误:内爆():参数#2($array)必须是类型?数组,字符串在 - PHP Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in WP-Statistics Uncaught TypeError: implode(): Argument #2 ($array) must be of type?array, string given - WP-Statistics Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given implode(): 参数 #2 ($array) 必须是类型?数组,给定字符串,是我在显示复选框值时收到的错误 - implode(): Argument #2 ($array) must be of type ?array, string given, is an error I receive in displaying a value of checkbox PHP 致命错误:未捕获类型错误:count():参数 #1 ($value) 必须是 Countable|array 类型,字符串在 - PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in 未捕获的类型错误:array_unique():参数 #1 ($array) 必须是数组类型,字符串在 C:\xampp\htdocs\ncapro\112.php:27 中给出 - Uncaught TypeError: array_unique(): Argument #1 ($array) must be of type array, string given in C:\xampp\htdocs\ncapro\112.php:27 参数 1 通过,必须是数组类型,给定字符串 - Argument 1 passed, must be of the type array, string given PHP 未捕获的类型错误:array_merge():参数 #1 必须是数组类型,给定 null - PHP Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given 致命错误:未捕获的类型错误:explode():参数 #2 ($string) 必须是字符串类型,给定数组 - Fatal error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, array given array_push(): 参数 #1 ($array) 必须是数组类型,给定字符串 - array_push(): Argument #1 ($array) must be of type array, string given join(): 参数 #2 ($array) 必须是类型?数组,给定字符串 - join(): Argument #2 ($array) must be of type ?array, string given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM