2016-06-11 44 views
-1
Array 
(
[0] => Array 
    (
     [intID] => 3 
     [intVolumeType] => 1 
     [intVolume] => 10 
     [totalVolumes] => 10 
     [intTrack] => 10 
     [intTrackType] => 2 
     [totalTracks] => 10 
    ) 

[1] => Array 
    (
     [intID] => 4 
     [intVolumeType] => 2 
     [intVolume] => 100 
     [totalVolumes] => 200 
     [intTrack] => 111 
     [intTrackType] => 3 
     [totalTracks] => 222 
    ) 

遍歷數組,類似物品首先在PHP

我想打印上述陣列:
intVolumeType = 1個
totalVolumes = 10
intVolumeType = 2
totalVolumes = 200


intTrackType = 2
totalTracks = 10
intTrackType = 3
totalTracks = 222

如何循環訪問此PHP數組。數組中共有六個元素。這可能會增加高達20打印首卷信息,比追蹤等on.Please幫助

回答

0

試試這個位置:http://phpfiddle.org/

<?php 
$a = Array 
    (
    0 => [ 
     'intID' => 3, 
     "intVolumeType" => 1, 
     "intVolume" => 10, 
     "totalVolumes" => 10, 
     "intTrack" => 10, 
     "intTrackType" => 2, 
     "totalTracks" => 10, 
    ], 
    1 => [ 
     "intID" => 4, 
     "intVolumeType" => 2, 
     "intVolume" => 100, 
     "totalVolumes" => 200, 
     "intTrack" => 111, 
     "intTrackType" => 3, 
     "totalTracks" => 222, 
    ] 
); 
/*echo "<pre>"; 
print_r($a); 
echo "</pre>"; 
*/ 
// you have to do it manually 
$volume = ""; 
$track = ""; 
foreach ($a as $item) { 
    // preparing for volumes types 
    $volume .= "intVolumeType = " . $item['intVolumeType'] . "<br/>"; 
    $volume .= "TotalVolumes = " . $item['totalVolumes'] . "<br/>"; 
    // you can add other variables too 
    $volume .= "<br/>"; 
    // preparing for track types 
    $track .= "intTrackType = " . $item['intTrackType'] . "<br/>"; 
    $track .= "TotalTracks = " . $item['totalTracks'] . "<br/>"; 
    // you can add other variables too 
    $track .= "<br/>"; 
} 
echo $volume; 
echo "===================<br/>"; 
echo $track; 
?>