Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Vendor\Model;
class Foo
{
const VERSION = '1.0';
const DATE_APPROVED = '2012-06-01';
}
<?php
// PHP 5.2.x and earlier:
class Vendor_Model_Foo
{
}
<?php
// PHP 5.3 and later:
namespace Vendor\Model;
class Foo
{
}
<?php
// declaration
function foo()
{
// function body
}
// conditional declaration is *not* a side effect
if (! function_exists('bar')) {
function bar()
<?php
// side effect: change ini settings
ini_set('error_reporting', E_ALL);
// side effect: loads a file
include "file.php";
// side effect: generates output
echo "<html>\n";
class Solution {
func finalPrices(_ prices: [Int]) -> [Int] {
var answer = [Int]()
for (index, price) in prices.enumerated() {
if index+1 == prices.count {
answer.append(price)
} else {
if price >= prices[index+1] {
let discount = prices[index+1]
override func viewDidLoad() {
super.viewDidLoad()
}
func swapTwoInts(a: Int, b: Int) -> (Int, Int) {
(b, a)
}
var firstNumber = 10
var secondNumber = 30
print("firstNumber : \(firstNumber)")
print("secondNumber : \(secondNumber)")
func swapTwoIntsWithInout(a: inout Int, b: inout Int) {
let temporaryA = a
a = b
b = temporaryA
}
var firstNumber = 10
var secondNumber = 30
import UIKit
import PlaygroundSupport
class TestViewController : UIViewController {
let labelOne: UILabel = {
let label = UILabel()
label.text = "Scroll Top"
label.backgroundColor = .red
label.translatesAutoresizingMaskIntoConstraints = false