200-530 | 200-550 | 200-710
1 | echo '1' . ( print '2' ) + 3; |
1 2 3 4 5 6 7 | $a = 3; switch ( $a ) { case 1: echo 'one' ; break ; case 2: echo 'two' ; break ; default : echo 'four' ; break ; case 3: echo 'three' ; break ; } |
1 2 | $a = 'a' ; $b = 'b' ; echo isset( $c ) ? $a . $b . $c : ( $c = 'c' ). 'd' ; |
1 | echo "1" + 2 * "0x02" ; |
1 | 1 ^ 2 |
1 | echo "22" + "0.2" , 23 . 1; |
1 2 3 | $first = "second" ; $second = "first" ; echo $$ $first ; |
1 2 3 4 5 6 7 | namespace MyFramework\DB; class MyClass { static function myName() { return __METHOD__ ; } } print MyClass::myName(); |
1 2 3 4 5 6 7 8 9 10 11 | // test.php: include "MyString.php" ; print "," ; print strlen ( "Hello world!" ); // MyString.php: namespace MyFramework\String; function strlen ( $str ) { return \ strlen ( $str )*2; // return double the string length } print strlen ( "Hello world!" ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class C { public $ello = 'ello' ; public $c ; public $m ; function __construct( $y ) { $this ->c = static function ( $f ) { // INSERT LINE OF CODE HERE }; $this ->m = function () { return "h" ; }; } } $x = new C( "h" ); $f = $x ->c; echo $f ( $x ->m); |
1 2 3 4 5 6 7 8 | function z( $x ) { return function ( $y ) use ( $x ) { return str_repeat ( $y , $x ); }; } $a = z(2); $b = z(3); echo $a (3) . $b (2); |
1 2 | $f = function () { return "hello" ; }; echo gettype ( $f ); |
1 2 3 4 5 6 7 8 | class C { public $x = 1; function __construct() { ++ $this ->x; } function __invoke() { return ++ $this ->x; } function __toString() { return (string) -- $this ->x; } } $obj = new C(); echo $obj (); |
1 2 3 4 5 6 7 8 9 10 11 12 | abstract class Base { protected function __construct() {} public static function create() { return new self(); // KEYWORD } abstract function action(); } class Item extends Base { public function action() { echo __CLASS__ ; } } $item = Item::create(); $item ->action(); // outputs "Item" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Base { protected static function whoami() { echo "Base " ; } public static function whoareyou() { static ::whoami(); } } class A extends Base { public static function test() { Base::whoareyou(); self::whoareyou(); parent::whoareyou(); A::whoareyou(); static ::whoareyou(); } public static function whoami() { echo "A " ; } } class B extends A { public static function whoami() { echo "B " ; } } B::test(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class Test { public function __call( $name , $args ) { call_user_func_array( array ( 'static' , "test$name" ), $args ); } public function testS( $l ) { echo "$l," ; } } class Test2 extends Test { public function testS( $l ) { echo "$l,$l," ; } } $test = new Test2(); $test ->S( 'A' ); |
1 2 | $obj = new MyObject(); array_walk ( $array , $obj ); |
1 2 3 4 5 6 7 8 9 10 11 12 | # __invoke() # The __invoke() method gets called when the object is called as a function . # When you declare it, you say which arguments it should expect. Here's a trivially simple example: class Butterfly { public function __invoke() { echo "flutter" ; } } # We can instantiate a Butterfly object, and then just use it like a function : $bob = new Butterfly(); $bob (); // flutter |
1 2 3 4 5 6 7 8 9 | class Magic { protected $v = array ( "a" => 1, "b" => 2, "c" => 3); public function __get( $v ) { return $this ->v[ $v ]; } } $m = new Magic(); $m ->d[] = 4; echo $m ->d[0]; |
1 2 3 4 5 6 7 | Table data (table name "users" with primary key "id" ): id name email ------- ----------- ------------------- 1 anna alpha@example.com 2 betty beta@example.org 3 clara gamma@example.net 5 sue sigma@example.info |
1 2 3 4 5 6 7 8 9 10 11 | $dsn = 'mysql:host=localhost;dbname=exam' ; $user = 'username' ; $pass = '********' ; $pdo = new PDO( $dsn , $user , $pass ); $cmd = "SELECT * FROM users WHERE id = :id" ; $stmt = $pdo ->prepare( $cmd ); $id = 3; $stmt ->bindParam( 'id' , $id ); $stmt ->execute(); $stmt ->bindColumn(3, $result ); $row = $stmt ->fetch(PDO::FETCH_BOUND); |
1 2 3 4 5 6 7 | Table data (table name "users" with primary key "id" ): id name email ------- ----------- ------------------- 1 anna alpha@example.com 2 betty beta@example.org 3 clara gamma@example.net 5 sue sigma@example.info |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $dsn = 'mysql:host=localhost;dbname=exam' ; $user = 'username' ; $pass = '********' ; $pdo = new PDO( $dsn , $user , $pass ); try { $cmd = "INSERT INTO users (id, name, email) VALUES (:id, :name, :email)" ; $stmt = $pdo ->prepare( $cmd ); $stmt ->bindValue( 'id' , 1); $stmt ->bindValue( 'name' , 'anna' ); $stmt ->bindValue( 'email' , 'alpha@example.com' ); $stmt ->execute(); echo "Success!" ; } catch (PDOException $e ) { echo "Failure!" ; throw $e ; } |
1 2 3 4 5 6 7 | Table data (table name "users" with primary key "id" ): id name email ------- ----------- ------------------- 1 anna alpha@example.com 2 betty beta@example.org 3 clara gamma@example.net 5 sue sigma@example.info |
1 2 3 4 5 6 7 8 9 | $dsn = 'mysql:host=localhost;dbname=exam' ; $user = 'username' ; $pass = '********' ; $pdo = new PDO( $dsn , $user , $pass ); $cmd = "SELECT name, email FROM users LIMIT 1" ; $stmt = $pdo ->prepare( $cmd ); $stmt ->execute(); $result = $stmt ->fetchAll(PDO::FETCH_BOTH); $row = $result [0]; |
1 2 3 4 5 6 7 | Table data (table name "users" with primary key "id" ): id name email ------- ----------- ------------------- 1 anna alpha@example.com 2 betty beta@example.org 3 clara gamma@example.net 5 sue sigma@example.info |
1 2 3 4 5 6 7 8 9 10 11 12 | $dsn = 'mysql:host=localhost;dbname=exam' ; $user = 'username' ; $pass = '********' ; $pdo = new PDO( $dsn , $user , $pass ); try { $pdo -> exec ( "INSERT INTO users (id, name, email) VALUES (6, 'bill', 'delta@example.com')" ); $pdo ->begin(); $pdo -> exec ( "INSERT INTO users (id, name, email) VALUES (7, 'john', 'epsilon@example.com')" ); throw new Exception(); } catch (Exception $e ) { $pdo ->rollBack(); } |
1 2 | $date1 = new DateTime( '2014-02-03' ); $date2 = new DateTime( '2014-03-02' ); |
1 | $date = new DateTime( '2014-03-15' ); |
1 2 3 4 | $obj = new C(); foreach ( $obj as $x => $y ) { echo $x , $y ; } |
1 2 3 4 5 6 7 8 | class Foo Implements ArrayAccess { function offsetExists( $k ) { return true;} function offsetGet( $k ) { return 'a' ;} function offsetSet( $k , $v ) {} function offsetUnset( $k ) {} } $x = new Foo(); echo array_key_exists ( 'foo' , $x )? 'true' : 'false' ; |
1 2 3 4 5 6 7 8 | class Bar { private $a = 'b' ; public $c = 'd' ; } $x = ( array ) new Bar(); echo array_key_exists ( 'a' , $x ) ? 'true' : 'false' ; echo '-' ; echo array_key_exists ( 'c' , $x ) ? 'true' : 'false' ; |
1 2 | $data = '$1Ä2' ; $count = strlen ( $data ); |
1 2 3 | $data = '$1Ä2' ; echo strlen ( $data ); // 5 echo mb_strlen( $data ); // 4 |
1 2 3 4 | $world = 'world' ; echo <<< 'TEXT' hello $world TEXT; |
1 | default_charset = utf-8 |
1 2 | header( 'Content-Type: text/html; charset=iso-8859-1' ); echo '✂✔✝' ; |
1 2 | $str = '✔ one of the following' ; echo str_replace ( '✔' , 'Check' , $str ); |
1 2 3 4 5 6 7 8 | $text = 'This is text' ; $text1 = <<< 'TEXT' $text TEXT; $text2 = <<<TEXT $text1 TEXT; echo "$text2" ; |
1 2 3 4 5 6 7 8 9 | function append( $str ) { $str = $str . 'append' ; } function prepend(& $str ) { $str = 'prepend' . $str ; } $string = 'zce' ; append(prepend( $string )); echo $string ; |
1 2 3 4 5 6 | function increment ( $val ) { $val = $val + 1; } $val = 1; increment ( $val ); echo $val ; |
1 2 3 4 5 6 | function increment ( $val ) { $val = $val + 1; } $val = 1; increment ( $val ); echo $val ; // output = 1 |
1 2 3 4 5 6 | function increment (& $val ) { $val = $val + 1; } $val = 1; increment ( $val ); echo $val ; // output = 2 |
1 2 3 4 5 6 | function increment ( $val ) { ++ $val ; } $val = 1; increment ( $val ); echo $val ; |
1 2 3 4 5 6 | function increment ( $val ) { ++ $val ; } $val = 1; increment ( $val ); echo $val ; // output = 1 |
1 2 3 4 5 6 | function increment (& $val ) { ++ $val ; } $val = 1; increment ( $val ); echo $val ; // output = 2 |
1 2 3 4 5 | function increment ( $val ) { $_GET [ 'm' ] = (int) $_GET [ 'm' ] + 1; } $_GET [ 'm' ] = 1; echo $_GET [ 'm' ]; |
1 2 3 4 5 6 7 8 9 | function counter( $start , & $stop ) { if ( $stop > $start ) { return ; } counter( $start --, ++ $stop ); } $start = 5; $stop = 2; counter( $start , $stop ); |
1 2 3 4 5 | 1x counter(5, 2) // $start = 5, $stop = 2 2x counter(5, 3) // $start-- = 5, ++$stop = 3 3x counter(5, 4) // $start-- = 5, ++$stop = 4 4x counter(5, 5) // $start-- = 5, ++$stop = 5 5x counter(5, 6) // $start-- = 5, ++$stop = 6 |
1 2 3 4 5 6 7 8 | function modifyArray (& $array ) { foreach ( $array as & $value ) { $value = $value + 1; } $value = $value + 2; } $array = array (1, 2, 3); modifyArray( $array ); |
1 2 3 4 5 6 7 8 9 | class a { public $val ; } function renderVal (a $a ) { if ( $a ) { echo $a ->val; } } renderVal (null); |
1 2 3 4 5 6 7 8 9 | function fibonacci (& $x1 = 0, & $x2 = 1) { $result = $x1 + $x2 ; $x1 = $x2 ; $x2 = $result ; return $result ; } for ( $i = 0; $i < 10; $i ++) { echo fibonacci() . ',' ; } |
1 2 3 4 5 6 | function ratio ( $x1 = 10, $x2 ) { if (isset ( $x2 )) { return $x2 / $x1 ; } } echo ratio (0); |
1 2 3 4 5 6 | function increment (& $val ) { return $val + 1; } $a = 1; echo increment ( $a ); echo increment ( $a ); |
1 2 3 4 5 6 7 8 9 10 | $getdata = "foo=bar" ; $opts = array ( 'http' => array ( 'method' => 'POST' , 'header' => 'Content-type: application/x-www-form-urlencoded' , 'content' => $getdata ) ); $context = stream_context_create( $opts ); |
1 | var_dump(boolval(-1)); |
1 | var_dump(boolval([])); |
1 | var_dump(boolval( new StdClass())); |
1 | $result = $value1 ??? $value2 ; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | trait MyTrait { private $abc = 1; public function increment() { $this ->abc++; } public function getValue() { return $this ->abc; } } class MyClass { use MyTrait; public function incrementBy2() { $this ->increment(); $this ->abc++; } } $c = new MyClass; $c ->incrementBy2(); var_dump( $c ->getValue()); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | trait A { public function hello() { return "hello" ; } public function world() { return "world" ; } } trait B { public function hello() { return "Hello" ; } public function person( $name ) { return ":$name" ; } } |
1 2 3 4 5 6 7 8 9 10 | class A { protected $x = array (); /* A */ public function getX() { /* B */ return $this ->x; /* C */ } } $a = new A(); /* D */ array_push ( $a ->getX(), "one" ); array_push ( $a ->getX(), "two" ); echo count ( $a ->getX()); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class A { public $a = 1; public function __construct( $a ) { $this ->a = $a ; } public function mul() { return function ( $x ) { return $this ->a* $x ; }; } } $a = new A(2); $a ->mul = function ( $x ) { return $x * $x ; }; $m = $a ->mul(); echo $m (3); |
1 2 | $m = $a ->mul(); echo $m (3); // output is 6 |
1 2 | $m = $a ->mul; echo $m (3); // output is 9 |
1 2 3 4 5 6 7 8 9 10 11 | class Number { private $v = 0; public function __construct( $v ) { $this ->v = $v ; } public function mul() { return function ( $x ) { return $this ->v * $x ; }; } } $one = new Number(1); $two = new Number(2); $double = $two ->mul()->bindTo( $one ); echo $double (5); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class Number { private $v ; private static $sv = 10; public function __construct( $v ) { $this ->v = $v ; } public function mul() { return static function ( $x ) { return isset( $this ) ? $this ->v* $x : self:: $sv * $x ; }; } } $one = new Number(1); $two = new Number(2); $double = $two ->mul(); $x = Closure::bind( $double , null, 'Number' ); echo $x (5); |
1 2 | $a = array_merge ([1,2,3] + [4=>1,5,6]); echo $a [2]; |
1 2 3 4 5 6 7 8 9 10 11 | $array = array (1, "hello" , 1, "world" , "hello" ); print_r( array_count_values ( $array )); /* output Array ( [1] => 2 [hello] => 2 [world] => 1 ) */ |
1 2 3 4 | $age = $mysqli ->real_escape_string( $_GET [ 'age' ]); $name = $mysqli ->real_escape_string( $_GET [ 'name' ]); $query = "SELECT * FROM `table` WHERE name LIKE '$name' AND age = $age" ; $results = $mysqli ->query( $query ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 | // SQL injections $query = "SELECT id, title, body FROM posts WHERE id = " . mysql_real_escape_string( $_GET [ 'id' ]); // This can still be injected: 1 OR 1=1 // Resulting in: SELECT id, title, body FROM posts WHERE id = 1 OR 1=1 // All results are returned. Not convinced this is bad? Ok... 1 OR 1=1 UNION SELECT id, username, password FROM users // Whoops! Why is this injectable? The developer just forgot to quote the numeric ID. |
1 | http_response_code( $code ); |
1 2 3 4 5 6 7 8 9 10 11 | class test { public $value = 0; function test() { $this ->value = 1; } function __construct() { $this ->value = 2; } } $object = new test(); echo $object ->value; |
1 2 3 4 | class T { const A = 42 + 1; } echo T::A; |
1 2 | const MY_CONSTANT; echo MY_CONSTANT; // Output: syntax error, unexpected ';', expecting '=' |
1 2 3 4 5 6 7 8 | define( 'PI' , 3.14); class T { const PI = PI; } class Math { const PI = T::PI; } echo Math::PI; |
1 2 3 4 | function f(stdClass & $x = NULL) { $x = 42; } $z = new stdClass; f( $z ); var_dump( $z ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | try { class MyException extends Exception {}; try { throw new MyException; } catch (Exception $e ) { echo "1:" ; throw $e ; } catch (MyException $e ) { echo "2:" ; throw $e ; } } catch (Exception $e ) { echo get_class( $e ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | abstract class Graphics { abstract function draw( $im , $col ); } abstract class Point1 extends Graphics { public $x , $y ; function __construct( $x , $y ) { $this ->x = $x ; $this ->y = $y ; } function draw( $im , $col ) { ImageSetPixel( $im , $this ->x, $this ->y, $col ); } } class Point2 extends Point1 { } abstract class Point3 extends Point2 { } |
1 2 3 4 5 | <?xml version= "1.0" encoding= "utf-8" ?> <books> <book id= "1" >PHP 5.5 in 42 Hours</book> <book id= "2" >Learning PHP 5.5 The Hard Way</book> </books> |
1 | (Let $xml = simplexml_load_file( "books.xml" ); .) (Choose 2) |
1 2 3 4 5 6 | <?xml version= '1.0' ?> <document> <bar> <foo>Value</foo> </bar> </document> |
1 2 3 4 5 6 7 | <?xml version= '1.0' ?> <foo> <bar> <baz id= "1" >One</baz> <baz id= "2" >Two</baz> </bar> </foo> |
1 2 3 4 | for ( $i = 0; $i < 1.02; $i += 0.17) { $a [ $i ] = $i ; } echo count ( $a ); |
1 2 | $a = array ( 'a' , 'b' , 'c' ); $a = array_keys ( array_flip ( $a )); |
1 2 3 4 5 6 7 8 | // isset() does not return TRUE for array keys that correspond to a NULL value, while array_key_exists() does. $search_array = array ( 'first' => null, 'second' => 4); // returns false isset( $search_array [ 'first' ]); // returns true array_key_exists ( 'first' , $search_array ); |
1 | $foo = array (true, '0' => false, false => true); |
1 | array_combine ( array ( "A" , "B" , "C" ), array (1,2,3)); |
1 | $array = array ( "Sue" , "Mary" , "John" , "Anna" ); |
1 2 3 | $array = array (1,2,3); while (list(, $v ) = each( $array )); var_dump(current( $array )); |
1 2 3 | $a = array (0, 1, 2 => array (3, 4)); $a [3] = array (4, 5); echo count ( $a , 1); |
1 | $a = array (28, 15, 77, 43); |
1 2 3 4 | $text = <<<EOT The big bang bonged under the bung. EOT; preg_match_all( '@b.n?g@' , $text , $matches ); |
1 | echo strtr ( 'Apples and bananas' , 'ae' , 'ea' ) |
1 2 | Apples end benenes // 1st: change a -> e, note Apples has not been changed Applas end benenes // 2nd: change e -> a, only where it has not been changed yet, that is, Apples change to Applas |
1 | printf( '%010.6f' , 22); |
1 | echo 0x33, ' monkeys sit on ' , 011, ' trees.' ; |
1 | preg_match( '/^\d+(?:\.[0-9]+)?$/' , $test ); |
1 | preg_match( '/^(\d{1,2}([a-z]+))(?:\s*)\S+ (?=201[0-9])/' , '21st March 2014' , $matches ); |
1 2 | $str = "The cat sat on the roof of their house." ; $matches = preg_split( "/(the)/i" , $str , -1, PREG_SPLIT_DELIM_CAPTURE); |
1 | md5(rand(), TRUE); |
1 | strpos ( "me myself and I" , "m" , 2) |
1 | $pieces = explode ( "/" , "///" ); |
1 2 | $test = '/etc/conf.d/wireless' ; substr ( $test , strrpos ( $test , '/' )); // note that strrpos() is being called, and not strpos() |
1 | <input type= "file" name= "myFile" /> |
1 2 3 4 | move_uploaded_file( $_FILES [ 'myFile' ][ 'tmp_name' ], 'uploads/' . $_FILES [ 'myFile' ][ 'name' ] ); |
1 2 3 | <form method= "post" > <input type= "checkbox" name= "accept" /> </form> |
1 2 3 4 5 6 7 | <form method= "post" > <select name= "list" > <option>one</option> <option>two</option> <option>three</option> </select> </form> |
1 | <input type= "image" name= "myImage" src= "image.png" /> |
1 2 3 4 | <?php $array = array (true => 'a' , 1 => 'b' ); print_r( $array ); ?> |
1 2 3 | <?php echo str_replace ( array ( "Apple" , "Orange" ), array ( "Orange" , "Apple" ), "Oranges are orange and Apples are green" ); ?> |
1 2 3 4 5 6 7 8 9 | class C { private static $x = 5; public static function getX() { return self:: $x ; } } echo C::getX(); // 5 |
1 2 3 4 5 6 7 8 9 10 11 12 | <html> <head> <title> This is a test script. </title> </head> <body> <?php echo 'This is some sample text' ; ?> </body> </html> |
1 2 3 4 5 6 7 8 | <?php $a =5; $b =12; $c =10; $d =7; $e =( $a * $b )+ $c * $d / $a ; print ( $e ); ?> |
1 2 3 4 5 6 7 | <?php $b = false; if ( $b = true) print ( "true" ); else print ( "false" ); ?> |
1 2 3 4 5 6 7 8 | <?php for ( $x = 1; $x <= 2; $x ++){ for ( $y = 1; $y <= 3; $y ++){ if ( $x == $y ) continue ; print ( "x = $x y = $y" ); } } ?> |
1 2 3 | <?php var_dump( (bool) 5.8 ); ?> |
1 2 3 4 5 6 7 | the boolean FALSE itself the integer 0 (zero) the float 0.0 (zero) the empty string, and the string "0" an array with zero elements the special type NULL (including unset variables) SimpleXML objects created from empty tags |
1 2 3 4 5 6 7 8 | <?php $a = array (1, 2, 3); $b = array (1 => 2, 2 => 3, 0 => 1); $c = array ( 'a' => 1, 'b' => 2, 'c' => 3); var_dump ( $a == $b ); var_dump ( $a === $b ); var_dump ( $a == $c ); ?> |
1 2 3 4 5 | <?php function magic( $p , $q ) { return ( $q == 0) ? $p : magic( $q , $p % $q ); } ?> |
1 2 3 | <?php echo strtotime ( "january 1, 1901" ); ?> |
1 2 3 | <?php echo date ( "M-d-Y" , mktime (0, 0, 0, 12, 32, 1995)); ?> |
1 2 3 4 5 6 7 | <?php $x =25; while ( $x <10) { $x --; } print ( $x ); ?> |
1 | $a = `ls -l`; |
1 2 3 | <?php echo date ( "M-d-Y" , mktime (0, 0, 0, 12, 32, 1965)); ?> |
1 2 3 4 5 6 7 8 9 10 11 12 | <html> <head> <title> This is a test script. </title> </head> <body> <?php echo (int) ((0.1 + 0.7) * 10); ?> </body> </html> |
1 2 3 4 5 | <?php define( 'FOO' , 10); $array = array (10 => FOO, "FOO" => 20); print $array [ $array [FOO]] * $array [ "FOO" ]; ?> |
1 2 3 4 5 6 7 | <?php switch (1) { case 1: print ( "Book Details" ); case 2: print ( "Book Author" ); default : print ( "Missing Book" ); } ?> |
1 2 3 4 5 6 7 8 9 | <?php $x =0; $i ; for ( $i =0; $i <5; $i ++) { $x += $i ; } print ( $x ); ?> |
1 2 3 4 5 6 7 8 9 | <?php function modvalue() { $a =20; $b =4; $c = $a % $b ; print ( $c ); } modvalue(); ?> |
1 2 3 4 5 6 7 8 | <?php function calc() { $x =10; $b =++ $x ; print ( $b ); } calc(); ?> |
1 | $somearray = array ( "hi" , "this is a string" , "this is a code" ); |
1 2 3 4 | <?php define( "GREETING" , "How are you today?" ,TRUE); echo constant( "greeting" ); ?> |
1 2 3 4 | <?php define( "GREETING" , "How are you today?" ); echo constant( "greeting" ); ?> |
1 2 3 4 | <?php define( "GREETING" , "How are you today?" ,FALSE); echo constant( "greeting" ); ?> |
1 2 3 4 | <?php define( "GREETING" , "How are you today?" , 'USECASE' ); echo constant( "greeting" ); ?> |
1 2 3 | <php echo 0x33, ' birds sit on ' , 022, ' trees.' ; ?> |
1 2 3 4 5 6 7 8 9 | <?php $a ; for ( $a =1; $a <=100; $a ++) { if ( $a ==50) { continue ; } print ( $a ); } ?> |
1 2 3 4 5 6 7 8 9 | <?php $a = 20; function myfunction( $b ) { $a = 30; global $a , $c ; return $c = ( $b + $a ); } print myfunction(40) + $c ; ?> |
1 2 3 | <?php echo date ( 'l \t\h\e jS' ); ?> |
1 2 3 | <?php $x = 123 == 0123; ?> |
1 2 3 4 5 | $a = 1234; // decimal number $a = -123; // a negative number $a = 0123; // octal number (equivalent to 83 decimal) $a = 0x1A; // hexadecimal number (equivalent to 26 decimal) $a = 0b11111111; // binary number (equivalent to 255 decimal) |
1 2 3 4 5 | <?php $a =12; $b =11; $a > $b ? print ( $a ) : print ( $b ); ?> |
1 2 3 4 | <? $a =20%-8; echo $a ; ?> |
1 2 3 | <? echo (int) "1235Jason" ; ?> |
1 2 3 4 5 6 7 8 9 | <?php function odd() { for ( $i =1; $i <=50; $i = $i +2) { echo "$i" ; } } echo "The last value of the variable \$i: $i" ; ?> |
1 2 3 | <? echo (int) "Jason 1235" ; ?> |
1 2 3 4 5 | <?php $sale = 200; $sale = $sale - + 1; echo $sale ; ?> |
1 2 3 4 5 6 7 | <?php function add() { $x =10; $y =5; $x += $y ; } ?> |
1 2 3 4 5 | <? $a = "b" ; $b = 20; echo $ $a ; ?> |
1 2 3 4 5 6 | <? $a = "b" ; $b = 20; ${20} = $a ; echo ${ $b }; ?> |
1 2 3 4 | <? 10 = $a ; echo $a ; ?> |
1 2 3 4 5 | <?php $num = -123test; $newnum = abs ( $num ); print $newnum ; ?> |
1 2 3 4 | <?php $a = 6 - 10 % 4; echo $a ; ?> |
1 2 3 4 | <?php $a =5 < 2; echo ( gettype ( $a )); ?> |
1 2 3 4 5 6 7 8 9 10 | $a = 'myVar' ; switch ( $a ) { case 0: echo 'case 0' ; case 'myVar' : echo 'case myVar' ; case 'nothing' : echo 'case nothing' ; } |
1 2 3 4 5 | <?php $s = '<p>Hello</p>' ; $ss = htmlentities( $s ); echo $s ; ?> |
1 | print strpos ( 'Zend Certified Engineer' , 116); |
1 | mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) |
1 2 3 4 5 6 7 8 | <?php for ( $i = 5; ; $i ++) { if ( $i < 10) { break ; } } echo $i ; ?> |
1 2 3 4 | $a = 1; $b = 2; $c = 3; echo (++ $a ) + ( $b ++) + (++ $c ) + ( $a ++) + (++ $b ) + ( $c ++); |