What are the differences between PHP arrays and JavaScript objects, and how can this impact data manipulation and transfer between the two languages?

PHP arrays and JavaScript objects have similar key-value pair structures, but there are some key differences. PHP arrays can have both numerical and associative keys, while JavaScript objects only have string keys. This can impact data manipulation and transfer between the two languages when converting PHP arrays to JavaScript objects or vice versa.

// Convert PHP array to JavaScript object
$phpArray = array("key1" => "value1", "key2" => "value2");
$jsObject = json_encode($phpArray);
echo "<script> var jsObject = JSON.parse('".$jsObject."'); </script>";