【发布时间】:2016-03-04 06:21:31
【问题描述】:
我似乎无法让 asort/arsort 与我的代码一起正常工作。我最初使用的是 sort/asort。当我 print_r 数组出现排序时,我转到我的“createtable”函数,它只是按索引顺序打印值。有什么想法吗?
我的主文件中的代码段
//Sorts Array by value [Ascending]
asort($songArray);
print_r($songArray);
//Creates table [See inc_func.php]
CreateTable ($songArray);
引用函数
function CreateTable ($array)
{
/* Create Table:
* count given $array as $arrayCount
* table_start
* for arrayCount > 0, add table elements
* table_end
*/
$arrayCount = count($array);
echo '<table>';
echo '<th colspan="2"> "Andrews Favorite Songs"';
// as long as arraycount > 0, add table elements
for ($i = 0; $i < $arrayCount; $i++)
{
$value = $array[$i];
echo '<tr>';
echo '<td>'.($i+1).'</td>';
echo '<td>'.$value.'</td>';
echo '</tr>';
}
echo '</table>'.'<br>';
}
谢谢。
【问题讨论】: