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 cl开发者_StackOverflow社区ient.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>";
You could simply say:
echo "<p> Server says: ".$err['foo']."</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.
精彩评论