[nycphp-talk] Extracting an int from a query string.
John Campbell
jcampbell1 at gmail.com
Tue Nov 13 09:34:05 EST 2007
I often need to extract an integer from the query string, and I have a
bad tendency of doing it differently every time.
Lately I have been using the following:
$page_index = is_numeric($_GET['page']) ? (int)$_GET['page'] : null;
which can also be used like:
$page_index = is_numeric($_GET['page']) ? (int)$_GET['page'] : $default_page;
Is there a better or more idiomatic way of doing it? I know most
people hate seeing the ternary operator combined with assignment, and
I was wondering if there is a more readable one-liner that I am
missing.
Regards,
John Campbell
More information about the talk
mailing list