Similar method list in PHP, MySQL, JS

When developers works across PHP, MySQL, and JavaScript, developers often encounter methods or functions that perform similar operations in different languages. This blog highlights similar methods from these three technologies, providing a comparison of their functionality to help you understand their role in different environments.

List of Similar Method in PHP, MySQL, JS:

FunctionalityPHP MethodsJS MethodsMySQL Methods
explode explode() split() -
implode implode() join() -
String Length strlen($str) str.length CHAR_LENGTH(column)
Substring Extraction substr($str, $start, $length) str.substring(start, end) SUBSTRING(column, pos, len)
Array Length count($arr) arr.length COUNT(column)
Replace Substring str_replace(search, replace, str) str.replace(search, replace) REPLACE(column, from, to)
Find Position strpos($str, $search) str.indexOf(search) LOCATE(substr, str)
Round Numbers round($num) Math.round(num) ROUND(num)
Generate Random Numbers rand() or mt_rand() Math.random() RAND()
Get Current Date/Time date() new Date() NOW()
Lowercase Conversion strtolower($str) str.toLowerCase() LOWER(column)
Uppercase Conversion strtoupper($str) str.toUpperCase() UPPER(column)
Remove Whitespace trim($str) str.trim() TRIM(column)
Split String explode(delimiter, $str) str.split(delimiter) -
Join Array implode(delimiter, $arr) arr.join(delimiter) GROUP_CONCAT(column)
Convert to JSON json_encode($data), json_encode($value) JSON.stringify(obj), JSON.stringify(value) JSON_OBJECT(key, value)
Parse JSON json_decode($jsonStr) JSON.parse(jsonStr) JSON_EXTRACT(json, path)
Check for Substring strpos($str, $substring) !== false str.includes(substring) INSTR(column, substring)
Remove Array Element unset($arr[index]) arr.splice(index, 1) -
Reverse String strrev($str) str.split('').reverse().join('') -
Round Down floor($num) Math.floor(num) FLOOR(num)
Round Up ceil($num) Math.ceil(num) CEIL(num)
Find Minimum Value min($arr) Math.min(...arr) MIN(column)
Find Maximum Value max($arr) Math.max(...arr) MAX(column)
Absolute Value abs($num) Math.abs(num) ABS(column)
Power Calculation pow($base, $exp) Math.pow(base, exp) POW(base, exp)
Check If Array is_array($arr) - Array.isArray(arr)
Array Filter array_filter($arr, callback) arr.filter(callback) -
array merge array_merge($arr1, $arr2) arr1.concat(arr2) -
Sort Array sort($arr) arr.sort() ORDER BY column
Current Timestamp time() Date.now() UNIX_TIMESTAMP()
Replace in Array array_replace($arr, replacements) arr.map(val => val === x ? y : val) -
File Existance is_file(), file_exist(), is_dir(string $filename): bool - LOAD_FILE()
Convert To String (string) $value, strval($value) String(value), value.toString() CAST(value AS CHAR)
Convert To Integer (int) $value or (integer), intval($value) Number.parseInt(value) or +valueor ~~value CAST(value AS SIGNED)
Convert To Float (float) $value or (double), floatval($value) Number.parseFloat(value) or +value CAST(value AS DECIMAL)
Convert To Boolean (bool) $value or (boolean) Boolean(value) or !!value Interpreted as 0 or 1 in conditions
Convert To Array (array) $value, explode(delimiter, string) Array.from(value) -
Convert To Object (object) $value Object(value) -
From JSON json_decode($json) JSON.parse(json) -
To Date/Time DateTime::createFromFormat(), strtotime($string) new Date(value), Date.parse(value) CAST(value AS DATETIME)
Binary To Hex bin2hex($string) btoa(value) -
Hex To Binary hex2bin($string) atob(value) -
URL Encode urlencode(), rawurlencode() encodeURIComponent(), encodeURI() REPLACE()
Last Modified Time filemtime() - -
File Size filesize() - -
File Handling with Streams fopen(), fgets(), fread(), fwrite() - -
Directory Operations scandir(), mkdir(), rmdir() - -
Rename a file rename() - -
Delete a file unlink() - -
File/Directory Existence file_exists() - -
Writing to Files file_put_contents(), fwrite() - -
Reading Files file_get_contents(), fgets() - LOAD_FILE()
OOps! You are currently offline.