PHP Codeigniter中的多维数组

我需要根据从数据库中检索到的记录来构建多维数组.

这是我的代码:

<?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'];
上一篇:php-Netbeans:代码格式化为CodeIgniter代码标准


下一篇:PHP-CodeIgniter:如果Active Record找不到任何数据,则返回FALSE