我需要根据从数据库中检索到的记录来构建多维数组.
这是我的代码:
<?php
/*
...some code...
*/
foreach($data['colleges'] as $college)
{
$college_temp[] = $college->name;
$college_temp[] = $college->abbrev;
$college_temp[] = $college->long_name;
$college_temp[] = $college->long_abbrev;
$college_temp[] = $college->url;
$college_temp[] = $college->description;
}
数据库中的所有记录都将在数组中一个接一个地移动.我需要使用多维数组对此进行优化.
解决方法:
$college_temp = array();
foreach($data['colleges'] as $college)
{
$college_temp[] = $college;
}
// Echo the first one's name
echo $college_temp[0]['name'];
// Echo the second one's url
echo $college_temp[1]['url'];