Follow

What's the most concise PHP syntax for "if not null, cast to int, otherwise use null"?

What I've got so far:

$var = (null !== $var) ? (int)$var : null;

Or:

if (null !== $var) { $var = (int)$var; }

Sign in to participate in the conversation
PHP Community on Mastodon

Open source. Open community. We are dedicated to building and enriching the PHP community.