Sujet : Re: New VSI post on Youtube
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vmsDate : 20. Aug 2024, 19:16:39
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <va2mi8$3f2e6$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Mozilla Thunderbird
On 8/20/2024 1:34 PM, bill wrote:
On 8/20/2024 8:36 AM, Simon Clubley wrote:
In languages with dynamic associative arrays (such as PHP), I simulate
this by returning an associative array from a function call with both
status and value fields. Makes coding _so_ much cleaner and robust.
And probably much harder to understand in anything but the most
trivial usage.
It is easy to understand if reasonable descriptive key names are chosen.
Example:
$ type mr.php
<?php
function four_ops($a, $b) {
return array('plus' => $a + $b, 'minus' => $a - $b, 'multiply' => $a * $b, 'divide' => $a / $b);
}
$a = 3.0;
$b = 2.0;
$res = four_ops($a, $b);
echo sprintf("%f + %f = %f\r\n", $a, $b, $res['plus']);
echo sprintf("%f - %f = %f\r\n", $a, $b, $res['minus']);
echo sprintf("%f * %f = %f\r\n", $a, $b, $res['multiply']);
echo sprintf("%f / %f = %f\r\n", $a, $b, $res['divide']);
?>
$ php mr.php
3.000000 + 2.000000 = 5.000000
3.000000 - 2.000000 = 1.000000
3.000000 * 2.000000 = 6.000000
3.000000 / 2.000000 = 1.500000
Arne