Php 显示对象数组的值

Php 显示对象数组的值,php,arrays,session,object,Php,Arrays,Session,Object,如何播放存储在会话中的对象数组的值 我是这样做的 <select name="countries" id="countries"> <?php foreach ($_SESSION['countries'] as $i=>$country ){?> <option><?php echo $_SESSION['countries'][$i]=>$country.getCountryName()?></

如何播放存储在会话中的对象数组的值

我是这样做的

<select name="countries" id="countries">
        <?php foreach ($_SESSION['countries'] as $i=>$country ){?>
        <option><?php echo $_SESSION['countries'][$i]=>$country.getCountryName()?></option>   //here's the error
        <?php
        }
    ?>
    </select>
//从数据库获取国家/地区数组

$countries = array();
    while($row = mysql_fetch_array($result)){

        $country = new Country();

        $country->setCountryName($row['country_name']);
        $country->setCountryNo($row['country_no']);
        $country->setCountryZipCode($row['country_zipcode']);

        $countries[]=$country;
    }

$_SESSION['countries']=$countries;
然后像这样显示会话的值

<select name="countries" id="countries">
        <?php foreach ($_SESSION['countries'] as $i=>$country ){?>
        <option><?php echo $_SESSION['countries'][$i]=>$country.getCountryName()?></option>   //here's the error
        <?php
        }
    ?>
    </select>

//这是错误
当我显示会话、任何帮助的值时出错?

请尝试以下操作:

<?php echo $country->getCountryName(); ?>


您不能在会话中保存对象。我很抱歉。但您可以将它们存储为属性数组,并在每次脚本启动时将其还原。

解析错误:语法错误,意外的T_双箭头,应为“,”或“;”在第14行的C:\AppServ\www\crm\subpage\SearchCustomer.sub.php中。第14行是打印会话值的位置出现此错误:main()[]:脚本试图执行方法或访问不完整对象的属性。请确保在调用unserialize()之前加载了您试图操作的对象的类定义“Country”,或者提供一个_autoload()函数来加载C:\AppServ\www\crm\subpages\SearchCustomer.sub.php中的类定义,我假设您在问题中发布的两个片段来自两个不同的脚本。在哪个文件中定义了
Country
类?您需要在显示
元素的脚本中包含该文件。我已经包含了具有country类的country文件,我尝试将echo设置为“hi”;它的工作方式和返回国家的数量相同。您确定我们不能在php会话中保存对象吗?您需要使用序列化: