user3618922
user3618922

Reputation: 181

PHP whats wrong with my syntax

I have this syntax here:

$savings = $savings == '' ? null : $savings;

$savings comes from $_POST['savings'] which comes from an input number field and I left it empty, so it should be equal to '' but when I print_r($savings) I get nothing, I was expecting null.

Upvotes: 0

Views: 56

Answers (1)

hsz
hsz

Reputation: 152216

Just try with:

$savings = empty($savings) ? null : $savings;

Upvotes: 3

Related Questions