Non well formed numeric value formed when using array_splice


I am using array_slice in PHP like so:

我在PHP中使用array_slice,如下所示:

if (isset($_GET['page']) && !isset($no_pagination)) {
        $page_num = mysql_real_escape_string($_GET['page']);
        $limit_value_from = $page_num * 10;
        $limit_value_to = $limit_value_from + 10;
        $limit_query = $limit_value_from.", ".$limit_value_to;
    }

if (!isset($no_pagination) && isset($limit_query)) {
        $usernames_new = array_splice($usernames, $limit_query);
        $usernames = $usernames_new;
    }

When I run the script it gives me this error: A non well formed numeric value encountered. When I echo the $limit_query string it gives me the correct 0, 10 10, 20 20, 30 values, and if I manually enter 0, 10 10, 20 etc. into the function it works fine. Why is this error happening even though it is properly formatted?

当我运行脚本时它给了我这个错误:遇到一个非常好的数值。当我回显$ limit_query字符串时,它给出了正确的0,10 10,20 20,30个值,如果我手动输入0,10 10,20等函数,它可以正常工作。为什么即使格式正确也会发生此错误?

Note: When I place the @ symbol before the array splice line the code works fine... Just wanted to know why this error is occurring.

注意:当我在数组拼接线之前放置@符号时代码工作正常...只是想知道为什么会发生这个错误。

1 个解决方案

#1


2  

You look to be passing the wrong arguments for that method. The second argument is an INT.

您希望为该方法传递错误的参数。第二个参数是INT。

array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = false ]] )

Try this:

$usernames_new = array_splice($usernames, $limit_value_from, $limit_value_to);

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com