我正在尝试将一个以HTML表格形式呈现的关联数组进行转换。这是该数组的样式:
Array ( [] => Harvest_Project Object (
[_root:protected] => project
[_tasks:protected] => Array ( )
[_convert:protected] => 1
[_values:protected] => Array (
[id] => \
[client-id] => -
[name] => Internal
[code] =>
[active] => false
[billable] => true
[bill-by] => none
[hourly-rate]=>-
以下是我在PHP中编写的将数组转换为表格的代码:
<?php
require_once(dirname(__FILE__) . '/HarvestAPI.php');
/* Register Auto Loader */
spl_autoload_register(array('HarvestAPI', 'autoload'));
$api = new HarvestAPI();
$api->setUser( $user );
$api->setPassword( $password );
$api->setAccount( $account );
$api->setRetryMode( HarvestAPI::RETRY );
$api->setSSL(true);
$result = $api->getProjects();
$data = $result->get( "data" );
echo "<table border='1'>
<tr><td>Project Name</td>
<td>Hourly Rate</td>
</tr>";
foreach($data as $key=>$fruit) {
?>
<tr><td><?php echo $fruit["Name"];?></td>
<td><?php echo $fruit["hourly-rate"];?></td></tr>
<?php ;}
echo "</table>";
?>
我想显示一个包含两列的表格 - 项目名称和每小时费率
但是一旦我执行代码,它会抛出一个错误“致命错误:无法在第24行使用Harvest_Project类型的对象作为数组。” 它是指这一行。
<tr><td><?php echo $fruit["Name"];?></td>
请建议如何处理这个问题。