PHP Dalsie priklady
- JurajSlovakID
- Používateľ
- Príspevky: 838
- Dátum registrácie: Po 13. Apr, 2015, 09:35
- Bydlisko: Spišská Nová Ves
PHP Dalsie priklady
ok tento kod ani nemal ist, pride dalsi prob. dam sem.
PC: CPU: RYZEN 5950X VMR-B2@ 4725MHz 1.35V , Chladic Arctic Liquid Freezer II RAM: GSKILL NEO 2x16KIT(32GB) 14-15-15-12-26-38 CR2 - upravene tercialne casovania, GFX: AMD Vega64, MB: Asus Dark Hero VIII X570, M.2 SSD Samsung 990 PRO 2TB, 2xRAID1 WDGOLD 8TB
- HellAngel
- Sponzor fóra gold
- Príspevky: 12736
- Dátum registrácie: Po 29. Dec, 2008, 00:15
- Bydlisko: Turčianske Teplice
Re: PHP Dalsie priklady
juraj prepac, ale mam dojem ze zakladas v poslednom case dost tem a v podstate su o nicom. Sorry za OT
NB: Asus ROG Strix G16 G614 + G Helper
- JurajSlovakID
- Používateľ
- Príspevky: 838
- Dátum registrácie: Po 13. Apr, 2015, 09:35
- Bydlisko: Spišská Nová Ves
Re: PHP Dalsie priklady
hej ja si to uvedomujem, mas pravdu, len na stackoverflow je tazke zalozit temu lebo ti ju musia schvalit a musi tam byt dobry nadpis inak ti to nezoberie neviem podla coho to vyhodnocuje... ked budem mat v buducnosti problem najprv pouvazujem potom google a sem to dam ako poslednu moznost.
dik
dik
PC: CPU: RYZEN 5950X VMR-B2@ 4725MHz 1.35V , Chladic Arctic Liquid Freezer II RAM: GSKILL NEO 2x16KIT(32GB) 14-15-15-12-26-38 CR2 - upravene tercialne casovania, GFX: AMD Vega64, MB: Asus Dark Hero VIII X570, M.2 SSD Samsung 990 PRO 2TB, 2xRAID1 WDGOLD 8TB
- JurajSlovakID
- Používateľ
- Príspevky: 838
- Dátum registrácie: Po 13. Apr, 2015, 09:35
- Bydlisko: Spišská Nová Ves
Re: PHP Dalsie priklady
tak tu mam 1. problem ktory moje snazenie neprekonalo:
<?php
class Entree {
public $name;
public $ingredients = array();
public function __construct($name, $ingredients) {
if (! is_array($ingredients)) {
throw new Exception('Ingrediements must be an array');
}
$this->name = $name;
$this->ingredients = $ingredients;
}
public function hasIngredient($ingredient) {
return in_array($ingredient, $this->ingredients);
}
}
class ComboMeal extends Entree {
public function hasIngredient($ingredient) {
foreach ($this->ingredients as $entree) {
if ($entree->hasIngredient($ingredient)) {
return true;
}
}
return false;
}
}
$soup = new Entree('Chicken Soup', array('chicken','water'));
$sandwich = new Entree('Chicken Sandwich', array('chicken','bread'));
$combo = new ComboMeal('Soup + Sandwich',array('$soup','$sandwich'));
foreach (['chicken','water','pickles'] as $ing) {
if ($combo->hasIngredient($ing)) {
print "Something in the combo contains $ing. <br>";
}
}
vypise:
Fatal error: Uncaught Error: Call to a member function hasIngredient() on string in C:\xampp\htdocs\index.php:21 Stack trace: #0 C:\xampp\htdocs\index.php(34): ComboMeal->hasIngredient('chicken') #1 {main} thrown in C:\xampp\htdocs\index.php on line 21
<?php
class Entree {
public $name;
public $ingredients = array();
public function __construct($name, $ingredients) {
if (! is_array($ingredients)) {
throw new Exception('Ingrediements must be an array');
}
$this->name = $name;
$this->ingredients = $ingredients;
}
public function hasIngredient($ingredient) {
return in_array($ingredient, $this->ingredients);
}
}
class ComboMeal extends Entree {
public function hasIngredient($ingredient) {
foreach ($this->ingredients as $entree) {
if ($entree->hasIngredient($ingredient)) {
return true;
}
}
return false;
}
}
$soup = new Entree('Chicken Soup', array('chicken','water'));
$sandwich = new Entree('Chicken Sandwich', array('chicken','bread'));
$combo = new ComboMeal('Soup + Sandwich',array('$soup','$sandwich'));
foreach (['chicken','water','pickles'] as $ing) {
if ($combo->hasIngredient($ing)) {
print "Something in the combo contains $ing. <br>";
}
}
vypise:
Fatal error: Uncaught Error: Call to a member function hasIngredient() on string in C:\xampp\htdocs\index.php:21 Stack trace: #0 C:\xampp\htdocs\index.php(34): ComboMeal->hasIngredient('chicken') #1 {main} thrown in C:\xampp\htdocs\index.php on line 21
PC: CPU: RYZEN 5950X VMR-B2@ 4725MHz 1.35V , Chladic Arctic Liquid Freezer II RAM: GSKILL NEO 2x16KIT(32GB) 14-15-15-12-26-38 CR2 - upravene tercialne casovania, GFX: AMD Vega64, MB: Asus Dark Hero VIII X570, M.2 SSD Samsung 990 PRO 2TB, 2xRAID1 WDGOLD 8TB
- JurajSlovakID
- Používateľ
- Príspevky: 838
- Dátum registrácie: Po 13. Apr, 2015, 09:35
- Bydlisko: Spišská Nová Ves
Re: PHP Dalsie priklady
vyriesene
malo byt
Kód: Vybrať všetko
$combo = new ComboMeal('Soup + Sandwich',array('$soup','$sandwich'));
Kód: Vybrať všetko
$combo = new ComboMeal('Soup + Sandwich',array($soup,$sandwich));
PC: CPU: RYZEN 5950X VMR-B2@ 4725MHz 1.35V , Chladic Arctic Liquid Freezer II RAM: GSKILL NEO 2x16KIT(32GB) 14-15-15-12-26-38 CR2 - upravene tercialne casovania, GFX: AMD Vega64, MB: Asus Dark Hero VIII X570, M.2 SSD Samsung 990 PRO 2TB, 2xRAID1 WDGOLD 8TB