0
$price = array(
    'value' => 40,
    'mo_desc' => array(
        'monthly' => 1,
        'quartely' => 0.95,
        'semi-anualy' => 0.90,
        'anualy' => 0.85,
        'bi-anualy' => 0.75
    ),
    'plan_desc' => array(
        'one' => 1,
        'two' => 1.9,
        'tree' => 3.6,
        'four' => 6.8,
        'five' => 9.6,
        'six' => 12,
        'seven' => 16.8,
        'eight' => 20.8
    )
);

変数の組み合わせを取得する必要があります。

$price_monthly_plan_one = $price['value'] * $price['mo_desc']['monthly'] * $price['plan_desc']['one'];
$price_quartely_plan_one = $price['value'] * $price['mo_desc']['quartely'] * $price['plan_desc']['one'];
$price_quartely_plan_two = $price['value'] * $price['mo_desc']['quartely'] * $price['plan_desc']['two'];

... for、while、foreach でいろいろ試しました。私はそれをすることはできません。誰かが助けてくれるなら!

$price を送信する関数を実行しようとしています。関数は次のような価格を返します。

$price = array(
    'plan_1' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx),
    'plan_2' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx),
    'plan_3' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx),
    'plan_4' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx),
    'plan_5' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx),
    'plan_6' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx),
    'plan_7' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx),
    'plan_8' => array ('price_monthly' => 40,'price_quartely' => xx,'price_semi-anualy' => xx,'price_anualy' => xx,'price_bianualy' => xx)
);

大変…とても大変…8時間以上挑戦!

4

2 に答える 2

0

これを試して:

<?php
$price = array(
    'value' => 40,
    'mo_desc' => array(
        'monthly' => 1,
        'quartely' => 0.95,
        'semi-anualy' => 0.90,
        'anualy' => 0.85,
        'bi-anualy' => 0.75
    ),
    'plan_desc' => array(
        'one' => 1,
        'two' => 1.9,
        'tree' => 3.6,
        'four' => 6.8,
        'five' => 9.6,
        'six' => 12,
        'seven' => 16.8,
        'eight' => 20.8
    )

);

$value = $price['value'];
$mo_desc = $price['mo_desc'];
$plan_desc = $price['plan_desc'];

foreach($mo_desc as $key=> $month) {

   echo '<h2>'.$key.'</h2>';

   foreach($plan_desc as $key1=> $plan) {
        echo '<br />Price '.$key. ' plan '.$key1.': ';
        $price = $value * $month * $plan;
        echo $price;
        echo ('<br />');
   }
}
于 2013-10-05T08:18:08.727 に答える
0

このコードを使用してください

<?php

$price = array(
    'value' => 40,
    'mo_desc' => array(
        'monthly' => 1,
        'quartely' => 0.95,
        'semi-anualy' => 0.90,
        'anualy' => 0.85,
        'bi-anualy' => 0.75
    ),
    'plan_desc' => array(
        'one' => 1,
        'two' => 1.9,
        'tree' => 3.6,
        'four' => 6.8,
        'five' => 9.6,
        'six' => 12,
        'seven' => 16.8,
        'eight' => 20.8
    )
);


    foreach ($price['mo_desc'] as $mo_desc_key=>$mo_desc_val) {
        foreach ($price['plan_desc'] as $plan_desc_key=>$plan_desc_val) {
            $var_name   = 'price_'.$mo_desc_key.'_plan_'.$plan_desc_key;
            $$var_name = $price['value'] * $mo_desc_val * $plan_desc_val;
        }
    }
echo $price_monthly_plan_one."<br>";  // Output 40
echo $price_quartely_plan_one."<br>"; // Output 38
echo $price_quartely_plan_two."<br>"; // Output 72.2
于 2013-10-05T08:10:06.330 に答える