Comparison between PHP and JS "problem solving" moduls (3) CODE
// Make the array in JS
const array = [0, 1, 2];
array[4] = 4;
console.log(array[3]);
// outputs "undefined"
/* at the third index the array will get the value "undefined" because the value - 4 will be placed at the fourth index and the code will not skip the third index */
// Make the array in PHP
$arr = [0, 1, 2];
$arr[4] = 4;
echo $arr[3];
// unlike JS, that code will not returns anything, there is nothing in 3rd index.
// another interesting fact about it console.log(array.length); // in JS echo (count($arr)); // in PHP // returns 5 in JS and 4 in PHP because in JS the 3rd index got the value - "undefined", but in PHP it just skipped the 3rd index and took the 4th position.
by Luka Khitaridze
2 years ago
PHP
JavaScript
Array difference
0
Pro tip: use ```triple backticks around text``` to write in code fences