From Diffen

[Edit Comparison Table]
Similarities (7) Differences (17) Show All (24)
To choose between PHP and Ruby, rate them on the comparison parameters by entering scores (+ve or -ve) in the comparison tool. The total points are automatically shown in the top row. This should help you decide.
PHP
Ruby

Rating: 3.2/5 (18 votes)

Rating: 3.4/5 (19 votes)

Language design goals:
Robustness and simplicity
Expressiveness, Readability
Statement terminators:
Semicolon terminated
Newline terminated
Inline comments delimiter:
// and #
#
Block comments delimiter:
/* and */
=begin and =end; also any text after __END__
Array element access:
$array[i]
array[i]
Array default base index:
0
0
Multidimensional arrays supported:
Yes
Yes
Arrays dynamically sized:
Yes
Yes
Vectorized operations:
Yes
Yes
String concatenation operator:
. (dot)
+ (the plus sign)
String comparison syntax:
strcmp(string1, string2)
string1 <=> string2
String equality testing syntax:
string1 == string2
string1 == string2
String search syntax:
strpos(string,substring[,startpos]) returns FALSE if search item (substring) not found
string.index(substring[,startpos]) returns nil if search item (substring) not found
String formatting syntax:
sprintf(formatstring, items)
sprintf(formatstring, items)
Syntax for joining an array of strings:
implode(separator, array_of_strings)
array_of_strings.join(separator)
Syntax for substring:
substr(string, startpos, numChars)
string[startpos, numChars]
Syntax for string length:
strlen(string)
string.size or string.length
Syntax for search and replace within string:
str_replace(find, replace, string)
string.gsub(find, replace)
Syntax for reversing a string:
strrev(string)
string.reverse
Syntax for converting string to upper case:
strtoupper(string)
string.upcase
Programming paradigms:
imperative, object-oriented, reflective
imperative, object-oriented, reflective, aspect-oriented
Typing:
Weak typing
Strongly typed
Type checking:
Dynamic
Dynamic
Intended use:
Web applications, CLI
Applications, scripting


PHP and Ruby are server-side scripting languages - most commonly used to develop web pages.

[edit] Associative Arrays in PHP vs. Ruby

[edit] PHP

PHP's built-in array type is in reality an associative array. Even when using numerical indexes, PHP internally stores it as an associative array. This is why one in PHP can have non-consecutive numerically indexed arrays. The keys have to be scalar values (string, floating point number or integer), while values can be of arbitrary types, including other arrays and objects. The arrays are heterogeneous; a single array can have keys of different types. PHP's associative arrays can be used to represent trees, lists, stacks, queues and other common data structures not built into PHP.

In PHP, an associative array can be formed in one of two ways:

$phonebook = array ();
$phonebook['Sally Smart'] = '555-9999'; $phonebook['John Doe'] = '555-1212'; 
$phonebook['J. Random Hacker'] = '555-1337'; 

// or 

$phonebook = array (
'Sally Smart' => '555-9999',
'John Doe' => '555-1212',
'J. Random Hacker' => '555-1337',
);

// or 
$phonebook['contacts']['Sally Smart']['number'] = '555-9999'; 
$phonebook['contacts']['John Doe']['number'] = '555-1212'; 
$phonebook['contacts']['J. Random Hacker']['number'] = '555-1337';

You can also loop through an associative array in PHP as follows:

foreach ($phonebook as $name => $number) {
echo "Number for $name: $number\n";
}
// For the last array example it is used like this 
foreach($phonebook['contacts'] as $name => $num) {
echo "Name:{$name}"; 
echo "Number:{$num['number']}"; 
}

PHP has an extensive set of functions to operate on arrays.

[edit] Ruby

In Ruby an associate array is called a Hash and is used as follows:

phonebook = {
'Sally Smart' => '555-9999', 'John Doe' => '555-1212', 'J. Random Hacker' => '553-1337'
}

phonebook['John Doe'] produces '555-1212'

To iterate over the hash, use something like the following:

phonebook.each {|key, value| puts key + " => " + value}

Additionally, each key may be shown individually:

phonebook.each_key {|key| puts key}

Each value may also be shown:

phonebook.each_value {|value| puts value}


PHP vs. Ruby - Chat Room

Edit Article
Diffen on Facebook

Comments: PHP vs Ruby  [Add Comments]

Comments on PHP vs. Ruby
I found this interesting article on one of the website http://www.hurricanesoftwares.com/php-vs-ruby/ Looks nice comparison too.
- by 125.18.56.179 on 2008-09-12 07:17:40