This commit is contained in:
Ingy döt Net 2013-04-10 16:57:12 -07:00
parent 518da4a923
commit 764da6cbbb
6144 changed files with 83610 additions and 11 deletions

View file

@ -0,0 +1,10 @@
# Using pack/unpack
$point = pack("ii", 1, 2);
$u = unpack("ix/iy", $point);
echo $x;
echo $y;
list($x,$y) = unpack("ii", $point);
echo $x;
echo $y;

View file

@ -0,0 +1,8 @@
# Using array
$point = array('x' => 1, 'y' => 2);
list($x, $y) = $point;
echo $x, ' ', $y, "\n";
# or simply:
echo $point['x'], ' ', $point['y'], "\n";

View file

@ -0,0 +1,7 @@
# Using class
class Point {
function __construct($x, $y) { $this->x = $x; $this->y = $y; }
function __tostring() { return $this->x . ' ' . $this->y . "\n"; }
}
$point = new Point(1, 2);
echo $point; # will call __tostring() in later releases of PHP 5.2; before that, it won't work so good.