Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
phpfiddle / fiddle_075706.php
Created August 26, 2015 03:05
[ Posted by Pramod Kadam ] Code refactoring
<?php
class First{
public function printP(){
print('P is great!');
}
}
class Second{
@phpfiddle
phpfiddle / 6552a3198e54a1dc3948b050722912a8.php
Last active August 27, 2015 12:23
[ Posted by JimmyLi ] if - elseif - random
<?php
$class = "Level 1";
$random = rand(0,3);
if($random==0)
{
$class = "Level 2";
}
elseif($random==1)
{
@phpfiddle
phpfiddle / fiddle_094226.php
Created August 27, 2015 12:25
[ Posted by LiviuS ] if , elseif , random
<?php
$class = "Level 1";
$random = rand(0,3);
if($random==0)
{
$class = "Level 2";
}
elseif($random==1)
{
@phpfiddle
phpfiddle / fiddle_059375.php
Created August 27, 2015 13:08
[ Posted by LiviuS ] while + if/elseif + random
<?php
$age = 0;
$message0 = "At first, ";
$message1 = "you are age ";
$message2 = "After a while: ";
$message3 = "you die!";
echo ($message0);
while($age<50){
@phpfiddle
phpfiddle / fiddle_071573.php
Created August 28, 2015 03:18
[ Posted by Subash ] foreach in php
<?php
$rows = [
'row1' => [
'color' => 'red',
'width' => '550px',
'img' => 'http://www.google.com.au/images/srpr/logo11w.png'
],
'row2' => [
'color' => 'black',
@phpfiddle
phpfiddle / fiddle_046804.php
Created August 28, 2015 12:57
[ Posted by LiviuS ] functions + if/elseif + random
<?php
function getClass(){
$class = "Level 1";
$random = rand(0,3);
if($random==0)
{
$class = "Level 2";
}
elseif($random==1)
@phpfiddle
phpfiddle / bd9ac5ec00167eb9270326e5655c7c3b.php
Last active August 28, 2015 13:05
[ Posted by LiviuS ] if, elseif, else $level += 10
<?php
$level=1;
while($level<50){
$random = rand(0,3);
if($random==0){
echo ("Level 0 message!<br/>");
$level += 10;
}
elseif($random==1){
echo ("Level 1 message!<br/>");
@phpfiddle
phpfiddle / fiddle_014530.php
Created August 28, 2015 13:18
[ Posted by LiviuS ] function + for + if/eleif + call function
<?php
function goOn($number){
for($i=0; $i < $number; $i++){
$name = "Apprentice";
$random = rand(0,3);
if($random==0)
{
$name = "Intermediate Apprentice <br/>";
}
@phpfiddle
phpfiddle / 19c763e8e5d37d254c5f98549b3ddb64.php
Created July 15, 2014 00:54
[ Posted by Fiddler ] cURL, XML parsing
<?php
/**
*
* cURL and XML parsing.
*
*/
$url = "http://www.w3schools.com/xml/simple.xml";
$ch = curl_init();
@phpfiddle
phpfiddle / fiddle_015091.php
Created July 15, 2014 21:01
[ Posted by Fiddler ] Test for time overlap
<?php
// Function to test for time overlap
// $start_time A start date YYYY-MM-DD HH:MM:SS
// $end_time An end date YYYY-MM-DD HH:MM:SS
// $times An array of times to match against
// Returns true if there is an overlap false if no overlap is found
function time_overlap($start_time, $end_time, $times){
$ustart = strtotime($start_time);
$uend = strtotime($end_time);