【问题标题】:Php array not working. whats wrong?php 数组不工作。怎么了?
【发布时间】:2017-12-17 11:11:09
【问题描述】:

我想使用 api。

这是我的代码:

// create a new purchase bill
$purchase = $parasut->make('sale')->create(array (
    'description'    => $siparis,
    'invoice_id'     => null,
    'invoice_series' => null,
    'currency'       => 'TRL',
    'item_type'      => 'invoice',
    'issue_date'     => $order_date_created,
    'due_date'       => $order_date_created,
    'contact_id'     => $contactToken,
    'category_id'    => null,
    'archived'       => false,
    'billing_address' => $user_address,
    'billing_fax'   => null,
    'billing_phone' => $user_phone,
    'details_attributes' => array (
        $parasut->make('product')->getProductFromOrder(), // the products
    ),
));

这里是 getProductFromOrder() 函数:

public function getProductFromOrder()
{
    $sku = array(5542003,5542004);
    $qty = array("3","1");
    $total = array("11.29","12.00");

    for($i=0; $i<count($sku); $i++){
        $urunler[$i] = array(
                    'product_id'     => $sku[$i], // the products
                    'quantity'       => '3',
                    'unit_price'     => '12.99',
                    'vat_rate'       => '18',
                    'discount_type'  => 'amount',
                    'discount_value' => '0',
            );
        print ($urunler[$i]);
    }
}

它不工作。当我运行第一个代码时,产品没有显示。哪里错了?

提前感谢您的帮助。

【问题讨论】:

标签: php arrays for-loop


【解决方案1】:

将函数getProductFromOrder()改为:

public function getProductFromOrder()
{
    $sku = array(5542003,5542004);
    $qty = array("3","1");
    $total = array("11.29","12.00");

    for($i=0; $i<count($sku); $i++){
        $urunler[$i] = array(
                    'product_id'     => $sku[$i], // the products
                    'quantity'       => '3',
                    'unit_price'     => '12.99',
                    'vat_rate'       => '18',
                    'discount_type'  => 'amount',
                    'discount_value' => '0',
            );
    }
    return $urunler;
}

使用return 代替print 并在for 循环之外写入return

【讨论】:

    猜你喜欢
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2011-03-01
    • 2011-06-28
    • 2023-01-12
    • 2021-04-14
    相关资源
    最近更新 更多