-1

我的数组是 Array ( [0] => Array ( [0] => Array ( [book_title] => Brief History of Time: From Big Bang to Black Hole [pd_id] => p22670689244706 [price] => 499.00 [author] => Stephen W. Hawking [book_type] => pb [status] => Pending ) ) [1] => Array ( [0] => Array ( [book_title] => The Art of Computer Programming, Volume 4A [pd_id] => p23662839087202 [price] => 899.00 [author] => Donald E. Knuth [book_type] => pb [status] => Pending ) ) )

如何在 codeigniter 的视图页面中打印book_title、定价?book_type

4

3 回答 3

1

鉴于您的数组被调用$array,您可以这样做:

foreach ($array as $arr) {
   foreach ($arr as $ar) {
      echo $ar['book_title'];
      echo $ar['price'];
      echo $ar['book_type'];
   }
}
于 2012-11-25T05:50:00.973 回答
1

您必须使用 foreach 循环两次才能获取值...

尝试这个...

foreach ($arrayName as $result){ // first loop gets all the value inside first array  
    foreach($result as $row){   //second gets the value inside the first array..
        echo $row['book_title'];
        echo $row['price'];
        echo $row['book_type'];
    }
}
于 2012-11-25T05:57:48.590 回答
0

在您的应用程序/视图文件夹中创建视图“listing.php”在其中添加此代码

<html>
<head>
<title>Book listing</title>
</head>
<body>
    <?php
    foreach ($books as $book) {           
     echo $book['book_title'] .' -- ' . $book['price'] .' -- ' . $book['book_type']. '<br>';
    }
?>
</body>
</html>

在您的控制器功能中编写这样的代码

$data['books'] = $yourArray; //@todo : replace your array name with $yourArray
$this->load->view('listing', $data);
于 2012-11-25T11:07:33.197 回答