2012-11-25 105 views
-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)))PHP數組輸出

如何打印book_title,價格,book_type鑑於頁面笨?

+0

控制器函數寫代碼創建新的視圖和控制器中,這將是足以表明你在視圖陣列添加。查看我的答案,下面有完整的描述 –

+0

看看tihs http://codeigniter.com/user_guide/general/views.html,請不要發佈問題,出去搜索它:(,有很多例子,只需鍵入「查看codeigniter「在谷歌 –

回答

1

鑑於你的數組稱爲$array,你可以這樣做:

foreach ($array as $arr) { 
    foreach ($arr as $ar) { 
     echo $ar['book_title']; 
     echo $ar['price']; 
     echo $ar['book_type']; 
    } 
} 
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']; 
    } 
} 
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);