在同一个数组中使用相同的Key值

时间:2011-09-24 01:24:03

标签: php arrays

如何正确编写此代码?第四行,我想在同一个数组中使用两个第一个键的值。

$pixel_percents = array(
    "complete"=>.5 * 768,
    "wip"=>round(.2 * 768, 0, PHP_ROUND_HALF_DOWN),
    "remain"=>$pixel_percents["complete"] - $pixel_percents["wip"]
);

2 个答案:

答案 0 :(得分:4)

之后再做
$pixel_percents = array(
    "complete"=>.5 * 768,
    "wip"=>round(.2 * 768, 0, PHP_ROUND_HALF_DOWN),
);
$pixel_percents['remain'] = $pixel_percents['complete'] - $pixel_percents['wip'];

答案 1 :(得分:3)

$pixel_percents = array();
$pixel_percents["complete"] = .5 * 768;
$pixel_percents["wip"] = round(.2 * 768, 0, PHP_ROUND_HALF_DOWN);
$pixel_percents["remain"] = $pixel_percents["complete"] - $pixel_percents["wip"];