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
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to