PHP and Ruby Syntax Quick Reference

Posted on   09-10-2011 11:15 by admin

PHP syntax :

Ruby : <% %>

PHP Comments : // /* */
Ruby Comments : # this is single line comment
=begin
this is multi line comment
this is the se ond line
=end


PHP Variable : $text = "onetwothree";
Ruby : x = "onetwothree"
Ruby class variable :@@total = 0
Ruby instance variable : @total = 10

PHP output : echo $text;
Ruby print x

Concatenation operator : . (dot)


Conditional Statement :
if (condition)
code;
else
code;

if (condition) {
code;
}elseif (condition){
code;
}else{
code;
}

Array: $cars=array("Saab","Volvo","BMW","Toyota");

$cars[0]="Saab";
$cars[1]="Volvo";
$cars[2]="BMW";
$cars[3]="Toyota";

Loops:
While Loop:
$i=1;
while($i<=5)
{
echo "The number is " . $i . "
";
$i++;
}

Do While loop:
$i=1;
do
{
$i++;
echo "The number is " . $i . "
";
}
while ($i<=5);

for Loop:
for ($i=1; $i<=5; $i++)
{
echo "The number is " . $i . "
";
}

foreach loop:
$x=array("one","two","three");
foreach ($x as $value)
{
echo $value . "
";
}

Form Handling:
$_GET -
$_POST -
$_REQUEST -

Include File
include("header.php");

    Source: www.w3schools.com, http://www.techotopia.com/index.php/Ruby_Number_Classes_and_Conversions
    Link: www.w3schools.com, http://www.techotopia.com/index.php/Ruby_Number_Classes_and_Conversions
Comments:
    www.u4nba.com on   27-08-2016 00:00
    This is really a nice place. www.u4nba.com http://nba2knews.publicoton.fr/nba-2k17-gameplay-reveals-cleveland-cavaliers-vs-golden-state-warriors-804296
    adult onesie on   12-07-2017 05:02
    I wanted to thank you for this excellent read!! I absolutely loved every bit of it. I have you saved as a favorite to check out new things you post… adult onesie https://www.grievebook.com/groups/when-did-onesie-pajamas-become-unironically-cool-holiday-g
 

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.