Question

I am using array_slice in PHP like so:

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?

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

Was it helpful?

Solution

You look to be passing the wrong arguments for that method. The second argument is an 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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top