<?php
class SimpleRobot {}
?>
<?php
class SimpleRobot {
function walk(){}
}
?>
<?php
class SimpleRobot {
var $power = "Electricity";
var $location = array('x'=>'0', 'y'=>'0');
function walk($direction){}
}
?>
<?php
$robot = new SimpleRobot();
?>
<?php
$robot = new SimpleRobot();
$robot->walk("left");
?>
<?php
$robot = new SimpleRobot();
echo $robot->power;
?>
<?php
class SimpleRobot {
var $power = "Electricity";
var $location = array('x'=>0, 'y'=>0);
function walk($direction) {
switch($direction){
case "left":
$this->location['x'] -= 1;
break;
case "right":
$this->location['x'] += 1;
break;
case "forward":
$this->location['y'] += 1;
break;
case "backward":
$this->location['y'] -= 1;
break;
}
}
}
?>
<?php
$robot1 = new SimpleRobot();
$robot2 = new SimpleRobot();
$robot1->walk("forward");
$robot2->walk("backward");
echo $robot1->location['y']; //outputs 1
echo $robot2->location['y']; //outputs -1
?>
<?php
for($i=1;$i>10000;$i++){
$robot$i = new SimpleRobot();
$robot$i->location['x'] = rand(1, 999);
$robot$i->location['y'] = rand(1, 999);
}
?>
<?php
class SimpleRobot {
var $power = "Electricity";
var $location = array();
function __construct($x = 0, $y = 0){
$this->location['x'] = $x;
$this->location['y'] = $y;
}
function walk($direction) {
switch($direction){
case "left":
$this->location['x'] -= 1;
break;
case "right":
$this->location['x'] += 1;
break;
case "forward":
$this->location['y'] += 1;
break;
case "backward":
$this->location['y'] -= 1;
break;
}
}
}
?>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Commented: