PHP:从服务器传递数组到客户端不工作!

The server Contents are server.php:

<?php 
$err["foo"]="bar";
?>

The client.php

<?php
require 'server.php';
echo "<p> Server says: $err['foo']</p>";
?>

But,This code works : The new server Contents are server.php:

<?php 
$err["foo"]="bar";
$errAssign=$err["foo"];
?>

The client.php

<?php
require 'server.php';
echo "<p> Server says: $errAssign</p>";
?>

Why am i not able to get the contents of the array from the server ?

Tried the following in the client.php

 echo "<p> Server says: $err[\'foo\']</p>";
 echo "<p> Server says: $err[\"foo\"]</p>";
 echo "<p> Server says: $err[foo]</p>";

None of which are working!!.. please help !!

You need to use braces for array and object access in ":

echo "<p> Server says: {$err['foo']}</p>";

Or if it were an object property/method:

echo "<p> Server says: {$err->foo}, {$err->getFoo()}</p>";

In client.php you must do:

<?php
require 'server.php';
echo "<p> Server says:" . $err['foo'] . "</p>";
?>

Much better, it must work. Note the "." symbol separator to use with strings.

You could simply say:

echo "<p> Server says: ".$err['foo']."</p>";