Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
phpfiddle / fiddle_097172.php
Created March 18, 2018 23:23
[ Posted by Adomas1237 ] asmkdaksmd
<?php
?>
@phpfiddle
phpfiddle / fiddle_025406.php
Created March 18, 2018 01:49
[ Posted by Alexey ] Geographical item list sorting
<?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",
@phpfiddle
phpfiddle / fiddle_059719.php
Created March 17, 2018 15:17
[ Posted by Alfred ] Please find absent number.
<?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
/**
@phpfiddle
phpfiddle / fiddle_050904.php
Created March 12, 2018 10:45
[ Posted by Sil Faber ] Opdracht 7
<?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) {
@phpfiddle
phpfiddle / fiddle_093347.php
Created March 2, 2018 10:23
[ Posted by Michael ] Verify that PHP objects are assigned and passed by reference
<?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) {
@phpfiddle
phpfiddle / fiddle_058280.php
Created February 23, 2018 12:04
[ Posted by Markus Flür ] usort example
<?php
class myClass{
public $id;
public function __construct($id){
$this->id = $id;
}
public function __toString(){
return "id is:".$this->id;
}
@phpfiddle
phpfiddle / fiddle_027521.php
Created February 22, 2018 08:15
[ Posted by Andrey.borue ] test123123123123
<?php
echo 123;
?>
<?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');
@phpfiddle
phpfiddle / fiddle_074847.php
Created February 14, 2018 05:52
[ Posted by Joshua Bohannon ] a5y3eeeeee
<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:
@phpfiddle
phpfiddle / fiddle_066372.php
Created January 10, 2018 04:36
[ Posted by Pgsutariya ] Color Code Array
<?php
$colorValue = "Red, Black, Brown";
$colors = explode(',', $colorValue);
$colorcods = array(
"800000" => "Maroon",
"8B0000" => "DarkRed",
"B22222" => "FireBrick",
"FF0000" => "Red",
"FA8072" => "Salmon",