This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://php.net/manual/en/function.json-decode.php | |
// parsing JSON data into assoc array | |
$data = json_decode(' | |
{ | |
"user": [ | |
{ | |
"beach_id": "1", | |
"name": "Crosby Beach", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* You are given an unsorted array of numbers from 1 to n (step 1). | |
* One number is absent in that array. Please find that number. | |
* I need a function | |
*/ | |
$arr = [2, 1, 3, 5]; // the array without one element, here it is 4 | |
$n = count($arr) + 1; // number of items inside array | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$spaargeld = 400; | |
$geldtekort = 1500 - $spaargeld; | |
$geldover = $spaargeld - 1500; | |
if ($spaargeld < 500) { | |
echo "Je spaargeld is nu: $spaargeld euro, je komt dus $geldtekort euro tekort!"; | |
} else if ($spaargeld > 499 && $spaargeld <1000) { | |
echo "Je spaargeld is nu: $spaargeld euro, je komt dus $geldtekort euro tekort!"; | |
} else if ($spaargeld >1499) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ages = [10, 15, 20]; | |
$persons = '[ | |
{"firstname":"John", "lastname":"Dryden", "age":20}, | |
{"firstname":"James", "lastname":"Zebedee", "age":25}, | |
{"firstname":"Michael", "lastname":"Orji", "age":30} | |
]'; | |
$persons = json_decode($persons); | |
foreach ($persons AS $key => $person) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class myClass{ | |
public $id; | |
public function __construct($id){ | |
$this->id = $id; | |
} | |
public function __toString(){ | |
return "id is:".$this->id; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo 123; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTopLevelDomain($url){ | |
$urlData = parse_url($url); | |
$urlHost = isset($urlData['host']) ? $urlData['host'] : ''; | |
$isIP = (bool)ip2long($urlHost); | |
if($isIP){ /** To check if it's ip then return same ip */ | |
return $urlHost; | |
} | |
$urlMap = array('com', 'com.pk', 'co.uk'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Memorial Day Sale</h2> | |
<ul><li>Compaq Presario m2007us Notebook: | |
<strong>$799.99</strong></li> | |
<li>Epson Stylus CX6600 Color All-In-One Printer, | |
Print/Copy/Scan: <strong>$699.99</strong></li> | |
<li>Proview Technology Inc. KDS K715s 17-inch LCD | |
Monitor, | |
Silver/Black: <strong>$199.99</strong></li> | |
<li>Hawking Technology Hi-Speed Wireless-G Cardbus | |
Card: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$colorValue = "Red, Black, Brown"; | |
$colors = explode(',', $colorValue); | |
$colorcods = array( | |
"800000" => "Maroon", | |
"8B0000" => "DarkRed", | |
"B22222" => "FireBrick", | |
"FF0000" => "Red", | |
"FA8072" => "Salmon", |