Shortest way to assign a default value to a variable?

dazee

New Member
I have this right now to use a cookie value if exists otherwise use a default value:\[code\]$default_carat_min = "0.25";if($_COOKIE["diamond-search_caratMin"]){ $default_carat_min = $_COOKIE["diamond-search_caratMin"];}\[/code\]I am going to have to do this with a lot of variables, and its going to get really cluttered/ugly. So I am trying to come up with a cleaner way of writing this.I tried:\[code\]$default_carat_min = $_COOKIE["diamond-search_caratMin"] | "0.25";\[/code\]Which did not work.I can do this: \[code\]$default_carat_min = $_COOKIE["diamond-search_caratMin"] ? $_COOKIE["diamond-search_caratMin"] : "0.25";\[/code\]But I don't like how I have to repeat the \[code\]$_COOKIE\[/code\] twice. I am wondering if there is a way to write it something like my 2nd example?
 
Back
Top