accnts = array(); foreach($accnts as $name => $val) { if(!is_string($name) || !is_int($val) || $val < 0) break; $this->accnts[$name] = $val; } } // Transfer accounts. function xfer($from, $to, $amt) { // Check and transfer. if(! array_key_exists($from, $this->accnts) || ! array_key_exists($to, $this->accnts)) return 0; if($this->accnts[$from] < $amt) return 0; $this->accnts[$from] -= $amt; $this->accnts[$to] += $amt; return 1; } // Find out how much is there. function bal($name) { if(! array_key_exists($name, $this->accnts)) return -1; return $this->accnts[$name]; } // Get the list of account names. function names() { return array_keys($this->accnts); } // Print out the accounts function pr($targs = "", $karg = 'style="text-align: right; padding-left: 10pt;"', $darg = 'style="text-align: left;"') { $keys = $this->names(); sort($keys); echo ""; foreach ($keys as $k) { echo ""; } echo "
$k:", $this->accnts[$k], "
"; } } ?>