A Beispiel 1

Auto-Kauf

Eingaben

B dbname = $dbname; $this->name = $name; $this->typ = $typ; $this->kw = $kw; $this->motor = $motor; $this->dab = $dab; $this->$sitzheizung = $sitzheizung; } public function print() { echo $this->name . ' ' . $this->typ . ' ' . $this->kw . ' ' . $this->motor; } } // Auto $autoArray=array(); function initAutos() { global $autoArray; $autoArray[] = new Auto('vw', 'VW', 'Golf', 123, 'Benzin', true, true); $autoArray[] = new Auto('vw', 'VW', 'Passat', 66, 'Diesel', true, false); $autoArray[] = new Auto('opel', 'Opel', 'Adam', 55, 'Benzin', true, false); $autoArray[] = new Auto('opel', 'Opel', 'Meriva', 155, 'Benzin-Hybrid', false, true); $autoArray[] = new Auto('bmw', 'BMW', '1', 45, 'Benzin', true, false); $autoArray[] = new Auto('bmw','BMW', '7', 156, 'Benzin', false, false); $autoArray[] = new Auto('peugeot', 'Peugeot', '208', 33, 'Benzin', true, true); $autoArray[] = new Auto('peugeot', 'Peugeot', '308', 66, 'Diesel', true, true); $autoArray[] = new Auto('peugeot', 'Peugeot', '508', 123, 'Elektro', true, true); } $ok = true; $firma=''; $error = ''; initAutos(); if ( isset($_GET['firma']) ){ // Ist gesetzt? $firma = $_GET['firma']; } else { $ok = false; $error.="Error: The param 'firma' are not passed
"; } if ($ok) { //echo count($autoArray ); $autos=array(); // Ergebnisfeld foreach ($autoArray as $auto) { if ($auto->dbname == $firma || $firma=='alles' ) { $autos[] = $auto; } } echo json_encode($autos); } else { echo $error; } ?>