There are many other differences between PHP and JavaScript arrays, which differ greatly in definition and operation. Now we're going to discuss the discussion.
1. We all know that PHP compares two arrays for equality (values, indexes)
$a =array (a); $b =array (a); echo ($a = = $b); Output is 1 if it's javascript: see the following code: <script type= "Text/javascript" > var a=[' A ', ' B ', ' C ']; var b=[' A ', ' B ', ' C ']; Console.log (a==b); Output is false </script>
What is this for? Because JavaScript objects are often reference types, comparisons of objects are reference comparisons that are equal when they refer to the same base object. The following code is based on the reference type array comparison
var a=[' A ', ' B ', ' C ']; var b=a; Console.log (a==b); Outupt is True
2.php and JavaScript are not the same about assigning an array object to a variable. JAVASCRPT only assigns a value to the reference value, and the object's province is not copied once, and PHP assigns a copy. may not be enough to understand, please look at the code:
<?php $a =array (a); $b = $a; $b []=6; Print_r ($a); Echo ' <br/> '; Print_r ($b); Array ([0] = 1 [1] = 2 [2] = 3) //array ([0] = 1 [1] = 2 [2] = 3 [3] = 6) JS Code: C6/>var a=[' A ', ' B ', ' C ']; var b=a; b[3]= ' d '; Console.log (a); Console.log (b); Output //["A", "B", "C", "D"] index12.html:12 //["A", "B", "C", "D"] index12.html:13
JS PHP Array Comparison