Php阵列无法正常工作。怎么了?

问题描述 投票:-4回答:1

我想和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个回答
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并在return循环外写入for

© www.soinside.com 2019 - 2024. All rights reserved.