Summary of differences between Python and PHP (comparison table of main items)

Summary of differences between Python and PHP (comparison table of main items)

Summary of differences between major items such as python and php classes and methods.

Preventing you from knowing which is which.


item Python PHP
function def function name(): function Function name(){}
End of processing new line ;
Comment out # // or /* */
variable Variable name $Variable name
Class definition class class name: class class name{}
constructor def __init__(self): Access right function__construct(){}
instance name of the class() newname of the class()
Property*1 Property name $Property name
Property call instance.Property name instance->Property name
Instance itself self $this
Call own property self.Property name $this->Property name
Method def method name(self) Access right function method name()
Method call instance.Method name() instance->Method name()
Inheritance class class name(Parent class name): class class name extends Parent class name{}
File reading import module name require_once(' ')
Class loading from module name import class name require_once(' ')
Parent class method call super().Method name() parent::Method name()
Class method @classmethod
def method name():
Access rights static function method name(){}
Calling a class method name of the class.Method name() name of the class::Method name()
Class properties (In line with the method definition)
Property name
Access rights static$Property name
Calling class properties name of the class.Property name name of the class::$Property name
output print() echo/print
Array [] array()
Array with keys {Key name:value} array(Key name=>value)
Array name with key Dictionary type Associative array
Number of elements in the array len(Array) count(Array)
Variable expansion*2 f'{variable}' "${variable}"
for statement for variable in range(Open price,closing price,Step)
※closing priceは含まない
for($Variable name=initial value:Conditional expression:Step){}
Extract one by one from the array for variable in array: foreach($Variable name as array)
if statement if conditional expression: if(Conditional expression){}
else if elif conditional expression: elseif (Conditional expression){}
switch statement None switch(){case condition:processing; break;}
and and &&/and
or or 2 pipes/or
Increment operator None ++
Decrement operator None --
Convert to integer type int() intval()
Convert to string type str() strval()
Type conversion to decimal point float() floatval()
3-digit separator '{:,d}'.format(Numerical value)
f'{Numerical value:,d}'
number_format()

If you look at it in a table, you can easily see the difference and regularity.

Recommended Posts

Summary of differences between Python and PHP (comparison table of main items)
Summary of the differences between PHP and Python
Comparison table of frequently used processes of Python and Clojure
A rough summary of the differences between Windows and Linux
Summary of Differences Between Ruby on Rails and Django ~ Basics ~
Differences between Python, stftime and strptime
Summary of Python indexes and slices
Differences in authenticity between Python and JavaScript
Differences between Ruby and Python in scope
Differences in syntax between Python and Java
Difference between PHP and Python finally and exit
[Basic grammar] Differences between Ruby / Python / PHP
Differences in multithreading between Python and Jython
Differences between Ruby and Python (basic syntax)
[Python] Summary of conversion between character strings and numerical values (ascii code)
Installation of Python3 and Flask [Environment construction summary]
Comparison of R and Python writing (Euclidean algorithm)
I / O related summary of python and fortran
Comparison of Python and Ruby (Environment / Grammar / Literal)
Differences in string processing between Python, Ruby, JS, PHP (combination and variable expansion)
Comparison of Python (+ Pandas), R, Julia (+ DataFrames) (summary of table contents, access by column)
Python --Explanation and usage summary of the top 24 packages
File write speed comparison experiment between python 2.7.9 and pypy 2.5.0
[Python] Type Error: Summary of error causes and remedies for'None Type'
[Ruby vs Python] Benchmark comparison between Rails and Flask
Difference between Ruby and Python in terms of variables
Indent behavior of json.dumps is different between python2 and python3
A quick comparison of Python and node.js test libraries
[Ubuntu] [Python] Face detection comparison between dlib and OpenCV
[Python] Summary of table creation method using DataFrame (pandas)
Summary of Python arguments
Summary of date processing in Python (datetime and dateutil)
Comparison of CoffeeScript with JavaScript, Python and Ruby grammar
[python] Summary of how to retrieve lists and dictionary elements
[Python] Summary of how to use split and join functions
Summary of Hash (Dictionary) operation support for Ruby and Python
Comparison of how to use higher-order functions in Python 2 and 3
Summary of python file operations
Summary of Python3 list operations
Comparison of 4 Python web frameworks
Comparison of Apex and Lamvery
Source installation and installation of Python
Note: Get the first and last items of Python OrderedDict non-destructively
Comparison of time series data predictions between SARIMA and Prophet models
Summary of installing PHP7.2 on EC2 (Amazon Linux 2) and setting php.ini
File open function in Python3 (difference between open and codecs.open and speed comparison)
[Python] Basic pattern and usage of if statement (comparison operator and Boolean operator)
[Comparison of PHP, Ruby, and Python description] For those who are wondering how the description method is different.
Environment construction of python and opencv
Difference between Ruby and Python split
Differences between Windows and Linux directories
Difference between java and python (memo)
The story of Python and the story of NaN
Difference between list () and [] in Python
Differences between yum commands and APT commands
Java and Python basic grammar comparison
Difference between == and is in python
Installation of SciPy and matplotlib (Python)
Anaconda and Python version correspondence table
[Python] [Table of Contents Links] Python Programming
Differences between symbolic links and hard links