Skip to content
Related Articles

Related Articles

Improve Article
Difference and Similarities between PHP and C
  • Last Updated : 28 Oct, 2020

PHP is a server-side scripting language designed specifically for web development. It can be easily embedded in HTML files and HTML codes can also be written in a PHP file. The thing that differentiates PHP with client-side language like HTML is, PHP codes are executed on the server whereas HTML codes are directly rendered on the browser.

C is a procedural programming language. It was initially developed by Dennis Ritchie as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and clean style, these features make C language suitable for system programming like an operating system or compiler development.

Similarities between PHP and C

ParametersSimilarities
Syntax
  1. Code is not sensitive to blanks.
  2. Semicolons are used for terminating a sentence.
  3. Functions are called in a similar fashion.
  4. Curly brackets are used for enclosing code in a block.
  5. C and C++ comment style is supported by PHP.
OperatorsAll type of operators in C behave in similar way in PHP, such as basic arithmetic, boolean, assignment and comparison operators.
Control Structure
  1. The primary control structures such as, if-else, while, for, do-while,etc function in similar way in both the languages.
  2. Break and continue are available in both PHP and C.
  3. Switch is also same, except that in PHP strings are also accepted as case identifiers.
Function prototypeUser defines functions are named in same way in both the languages.

Differences between PHP and C

ParametersPHPC
Data typesPHP has only two numerical data type:
  • integer(can be compared to long in C)
  • double(can be compared to double in C)

Strings are of random length and there is no character data type available in PHP.

C has:
  • Primary data types(such as int, double, float, char, void, etc.)
  • Derived data types(array, structure, union and pointer)
Type ConversionData types are not checked during compile-time and data type errors are rare to occur. Values and variables are automatically cast into the suitable data type.In C variables are declared with data types. While some data types have implicit conversion, others need to be type-casted.
Data type error occurs in C commonly and should be taken care.
ArraySuperficially they look similar to arrays in C.
  • Array need not be allocated or declared in advance.
  • The indexes can be opted by user- string or a number.
  • They are used for hashing are known as associative arrays.
  • Array needs to be allocated or declared in advance.
  • Their data types and memory allocation is done before they are used in the code.
  • The indexes can be only numbers starting from 0.
StructureNo structure type needed because of array and objects.Structure type exists in C.
PrototypesThere are no prototype in PHP because function is not required to be declared before it’s implementation.There are prototypes in C because function is required to be declared before its implementation.
PermissivenessPHP is a lot more lenient when compared to C. More than errors there are unexpected results for making new mistakes.C will give errors if data type is not declared, array size is not declared, etc.
Comparing it to PHP it is a little stricter.
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :