douzi4766 2016-03-08 13:56
浏览 55
已采纳

选择将哪个变量插入到数组中

I have two variables

$order_phone = $orders[$x]['phone'];
$order_mobile = $orders[$x]['mobile'];

Using a function out of the API i create a new array. Inside the array these variables will be set like this:

'telephone' => $order_phone . $order_mobile ,

Now I am getting into trouble when the length exceeds 20 characters. then I get this error:

Fatal error: Uncaught exception 'SendCloudApiException' with message 'telephone: "Ensure this field has no more than 20 characters."

Can I let the inserted variable be a choice? If 1 of the 2 is filled out let that variable be chosen or else always take the mobile number?

Below is the rest of the created array:

$createdParcel = $apiSend->parcels->create(

    array(
            'name'=> ($order_firstName . $order_middleName . $order_lastName),
            'company_name' => $order_companyName,
            'address' => ($order_addressBillingStreet . $order_addressBillingStreet2 . $order_addressBillingNumber . $order_addressBillingExtension),
            'city' => $order_addressBillingCity,
            'postal_code' => $order_addressBillingZipcode,
            'telephone' => $order_phone . $order_mobile ,
            'requestShipment' => false, // set to true when you want to request a shipment
            'email' => $order_email,
            'country' => strtoupper($order_addressBillingCountry['code']),
            'order_number' => $order_number
          )

);
  • 写回答

1条回答 默认 最新

  • dreljie602951 2016-03-08 14:10
    关注

    I really don't understand the usefullness of concatenated phone numbers, but here we go.

    // If both numbers together have a maximum legth of 20 chars: use them both
    if(strlen($order_phone . $order_mobile) <= 20) {
      $phone = $order_phone . $order_mobile;
    } else {
      if(!empty($order_mobile)) {
        // if a mobile number is given use that
        $phone = $order_mobile;
      } else {
        // Use phone number other wise
        $phone = $order_phone;
      }
    }
    // at this point $phone is a string <= 20 chars
    
    $createdParcel = $apiSend->parcels->create(
    
        array(
                'name'=> ($order_firstName . $order_middleName . $order_lastName),
                'company_name' => $order_companyName,
                'address' => ($order_addressBillingStreet . $order_addressBillingStreet2 . $order_addressBillingNumber . $order_addressBillingExtension),
                'city' => $order_addressBillingCity,
                'postal_code' => $order_addressBillingZipcode,
                'telephone' => $phone , // Use phone number from above
                'requestShipment' => false, // set to true when you want to request a shipment
                'email' => $order_email,
                'country' => strtoupper($order_addressBillingCountry['code']),
                'order_number' => $order_number
              )
    
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度