a79ce734e1
a79ce734e1

Reputation: 875

Using Same Value of Key in Same Array

How do I write this code correctly? The fourth line, I want to use the values of the two first keys all within the same array.

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

Upvotes: 1

Views: 68

Answers (2)

Jared Farrish
Jared Farrish

Reputation: 49198

$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"];

Upvotes: 3

paimoe
paimoe

Reputation: 709

Just do it after

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

Upvotes: 4

Related Questions