A table with header and no footer.
| Purpose | C# | Php4 | Php5 | ActionScript | JavaScript | Ruby |
|---|---|---|---|---|---|---|
| Declare an array | int[] x = new int[5]; |
// key only integer or string // value any $array = array(1, 2, 3, 4, 5); $arr = array("foo" => "bar", 12 => true); |
// key only integer or string // value any $array = array(1, 2, 3, 4, 5); $arr = array("foo" => "bar", 12 => true); |
var arr:Array = [1,2,3]; |
new Array() new Array(len) new Array([item0,[item1,[item2,...]]] //Example var objArray=new Array(); var arr=[0,1,2,3,4,5,6]; |
a = [ 1, 'cat', 3.14 ] |
| Initialize an array |
int[] x = new int[5] { 1, 2, 3, 4, 5}; |
$arr = array( "somearray" => array( 6 => 5, 13 => 9, "a" => 42)); |
$arr = array( "somearray" => array( 6 => 5, 13 => 9, "a" => 42)); |
var arr:Array = new Array(1,2,3); |
var arr=[0,1,2,3,4,5,6]; var complexArray = [[1,{x:1, y:2}], [2, {x:3, y:4}]]; |
inst_section = { 'cello' => 'string', 'trumpet' => 'brass', 'violin' => 'string' } |
| Add or remove element |
$arr["x"] = 42;
// This adds a new element to // the array with key "x" $array[] = 6; unset($arr[5]); // This removes the element from the array |
$arr["x"] = 42;
// This adds a new element to // the array with key "x" unset($arr[5]); // This removes the element from the array |
arr.push(item); arr.splice(at,count); |
// Add elements objArray.push([value1[,value2[,....]]]); //[1,2,3, 4].push("a","b") result is [1,2,3,4,"a","b"] objArray.pop(); //remove the last element[1,2,3, 4].pop() result is [1,2,3] objArray.shift(); //remove the first element. objArray.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]]) |
||
| Reallocate array | n/a |
// This deletes the whole array
unset($arr); |
// This deletes the whole array unset($arr); |
n/a | n/a |
Table with both header and footer.
| Purpose | C# | Php4 | Php5 | ActionScript | JavaScript | Ruby |
|---|---|---|---|---|---|---|
| Declare a variable |
// declarators // (keywords include user-defined types // and built-in types) |
// Only use var declare a class variable | // Only use var declare a class variable | var varName : Type; |
// var // No var means Globle variable, //but it should be initialized while it is used. |
Don’t declare |
| Declare a named constant | const readonly | define | define | const a:Number = 1; | n/a | begins with an uppercase letter (A-Z) |
| Create a new instance of a class | new | new | new | new |
new
//JavaScript does not support true classes. //it is possible to define pseudoclasses in JavaScript. |
Class method new |
| Create a new object | new | new | new | { memeberName : member } | new | |
| Assign an object to an object variable | = | = | = | = | = | = |
| Function/method does not return a value | void | function | function | function | function | def |
| Overload a function or method (Visual Basic: overload a procedure or method) | n/a | n/a | n/a | n/a | n/a | n/a |
| Refer to the current object | this | $this | $this | this | this | self |
| Make a nonvirtual call to a virtual method of the current object | // n/a | // n/a | // n/a | // n/a | // n/a | |
| Retrieve character from a string | str[10] // where str is a string |
$userName = "kimi"; Echo $userName[i] |
$userName = "kimi"; Echo $userName[i] |
str.charAt(3); |
var str = "I am a string."
document.write(str.charAt(0)); // get the first character. |
str[10] |
| Declare a compound data type (structure) | struct class interface | class | classinterface | n/a | class Struct | |
| Initialize an object (constructor) |
// Constructors // or system default type constructors // Class Constructors |
// Constructors // or system default type constructors // (concept, not keyword) |
function __construct() |
public class ClassA{ public ClassA(){} } |
// Constructors |
initialize |
| Terminate an object directly | n/a | n/a | n/a | n/a | ||
| Method called by the system just before garbage collection reclaims an object7 | Destructors | n/a | function __destruct() | n/a | n/a | |
| Guarantee that unmanaged resources are disposed of after use | using | n/a | n/a | n/a | n/a | |
| Initialize a variable where it is declared |
// initialize to a value: int x = 123; // or use default constructor: int x = new int(); |
$myString = 'test string'; $myInt = 12; |
$myString = 'test string'; $myInt = 12; |
var a : int = 1; |
// initialize to a value var x = 123; //or use default constructor: var str = new String("I am string."); |
my_array = [ 1, 2, 3 ] song = Song.new("Bicylops", "Fleck", 260) |
| Take the address of a function | delegate | n/a | n/a |
function abc(){} var ptr : Function = abc; |
n/a | method instance_method |
| Callback | delegate |
call_user_func function printName(){ echo "Mike"; } $v = "printName"; echo $v(); |
call_user_func function printName(){ echo "Mike"; } $v = "printName"; echo $v(); |
n/a | Method.call | |
| Declare that an object can be modified asynchronously | volatile | n/a | n/a | n/a | n/a | |
| Force explicit declaration of variables | // All variables must be declared prior to use n/a | n/a | n/a | n/a | n/a | |
| Enable local type inference | n/a | n/a | n/a | n/a | ||
| Test for an object variable that does not refer to an object | obj == null | $obj == nullis_null | $obj == nullis_null | obj == null | obj == null |
Obj == nil
nil? method |
| Value of an object variable that does not refer to an object | null | null | null | null | undefined or null | nil |
| Test for a database null expression | n/a | n/a | n/a | n/a | n/a | |
| Test whether a Variant variable has been initialized | n/a | empty() or isset() | empty() or isset() | varName==undefined |
var a; a == undefined; |
|
| Define a default property | Indexers | n/a | __toString | n/a | n/a | to_s |
| Object cloning | n/a | n/a | clone__clone | n/a | n/a | |
| Purpose | C# | Php4 | Php5 | ActionScript | JavaScript | Ruby |