Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
10
Task/Compound-data-type/PHP/compound-data-type-1.php
Normal file
10
Task/Compound-data-type/PHP/compound-data-type-1.php
Normal 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;
|
||||
8
Task/Compound-data-type/PHP/compound-data-type-2.php
Normal file
8
Task/Compound-data-type/PHP/compound-data-type-2.php
Normal 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";
|
||||
7
Task/Compound-data-type/PHP/compound-data-type-3.php
Normal file
7
Task/Compound-data-type/PHP/compound-data-type-3.php
Normal 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue