简体   繁体   中英

Referencing the Compared Variable in PHP

This feels like a really stupid question, but I've always wondered if I've been doing this wrong:

if($payment->shipping_state OR $payment->shipping_province)
    {
        $request['SHIPTOSTATE'] = isset($payment->shipping_state) ? $payment->shipping_state : $payment->shipping_province;
    }

Is there a keyword/an easier way to set $request['SHIPTOSTATE'] to the variable which exists, since I already confirmed one of the two do in fact exist?

Something like:

if ($payment->shipping_state OR $payment->shipping_province)
{
  $var = $this;
}
$data = (!empty($payment->shipping_state))?$payment->shipping_state:$payment->shipping_province;
if (!empty($data))
    $request['SHIPTOSTATE'] = $data;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM