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