Skip to content

Instantly share code, notes, and snippets.

Mohammad Shahrizal Prabowo rizalp

  • Indonesia
View GitHub Profile
@rizalp
rizalp / PHP: OOP
Created Apr 25, 2013
PHP: Important Object Oriented Snippet
View PHP: OOP
<?php
class Person {
private $name;
private $job;
//constructor. If no argument, then both $name and $job is null
public function __construct($name, $job){
$this->name = $name;
$this->job = $job;
}
@rizalp
rizalp / PHP: Packages
Created Apr 25, 2013
PHP: Code Management using Namespace, Package, Include/Require
View PHP: Packages
<?php
//INCLUDES / REQUIRES
//require vs include : require will stop execution if the script isn't found
require 'req/header.php' ;
require 'req/header.php' ;
//NAMESPACE
//append \ (root) before the name of the class if you want to call global function
namespace App\DB; //defining namespace
function connect(){
@rizalp
rizalp / PHP: Var & Function
Created Apr 25, 2013
PHP: Basic Usage of Variable, and Function
View PHP: Var & Function
<?php
//CONSTANTS
define('ABC', 'Abjad tiga pertama');
const RED = "red";
//Variables
$hello = "Shahrizal Prabowo";
$name = "John";
$$name = "Registered user"; //create pointer
print $John;
@rizalp
rizalp / PHP: Control Structure
Created Apr 25, 2013
PHP: Control Structure. Boolean operator, if, switch & loop usage
View PHP: Control Structure
<?php
// boolean ooperator
===, ==
>==, <==, >, <, !==
&&, ||
++
+=
// falsy value
'', "" = false;
@rizalp
rizalp / PHP: Array & String
Created Apr 25, 2013
PHP: Important usage of Array and String
View PHP: Array & String
<?php
$months = array(0, 1, 2, 3, 4, 5);
//only in PHP >= 5.4
$months = [0, 1, 2, 3, 4, 5];
// push into the end
$months[] = 6;
array_push($months, 7);
// Initialize array of consecutive Integer
View PHP: Superglobals
/********** Superglobals ***************/
<?php
// Variables that are created in the main script (not within a function)
// aren’t global variables; you cannot see them inside functions, but
// you can access them by using a special array $GLOBALS[] using
// the variable’s name as the string offset.
$PI = 3.14;
$radius = 5;
@rizalp
rizalp / PHP: Session & Cookie
Created Apr 25, 2013
PHP: Session & Cookie
View PHP: Session & Cookie
@rizalp
rizalp / PHP: PDO Usage Sample
Created Apr 25, 2013
PHP: PDO Usage Sample
View PHP: PDO Usage Sample
<?php
//config.php
$config = array(
'DB_USERNAME' => 'root',
'DB_PASSWORD' => 'tutsplus'
);?>
<?php
//another file
require 'config.php';
View PHP: Numbers
<?php
// ensure that a string contains a number
if (is_numeric('five')) { /* false */ }
if (is_numeric(5)) { /* true */ }
if (is_numeric('5')) { /* true */ }
if (is_numeric(-5)) { /* true */ }
if (is_numeric('-5')) { /* true */ }
// is_numeric( ) properly parses decimal numbers, such as 5.1;
@rizalp
rizalp / JavaScript: Var & Function.js
Last active Dec 16, 2015
JavaScript: Basic Variable & Function usage #JavaScript #Functions
View JavaScript: Var & Function.js
var variableName; //undefined
var helloWorld = "Hello, World!";
var ten = 10;
var pi = 3.14;
var isBoolean = false;
var sum = 4 + 5,
difference = 4 - 5,
product = 4 * 5,
quotion = 4 / 5;
You can’t perform that action at this time.