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
)
)
)
I want to print above array as:
intVolumeType = 1
totalVolumes = 10
intVolumeType = 2
totalVolumes = 200
我要打印上面的數組:intVolumeType = 1 totalvolume = 10 intVolumeType = 2 totalvolume = 200。
intTrackType = 2
totalTracks = 10
intTrackType = 3
totalTracks = 222
How to loop through this PHP array. There are total six elements in array. Which might increase upto 20. Print first Volume Information, than Track, and so on.Please help
如何循環這個PHP數組。數組中總共有6個元素。這可能會增加到20。打印第一卷信息,而不是跟蹤,等等。請幫助
1 个解决方案
#1
0
試試這個:http://phpfiddle.org/
$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 "
";
print_r( $a );
echo "
";*/
// you have to do it manually
$volume = "";
$track = "";
foreach ( $a as $item ) {
// preparing for volumes types
$volume .= "intVolumeType = " . $item['intVolumeType'] . "
";
$volume .= "TotalVolumes = " . $item['totalVolumes'] . "
";
// you can add other variables too
$volume .= "
";
// preparing for track types
$track .= "intTrackType = " . $item['intTrackType'] . "
";
$track .= "TotalTracks = " . $item['totalTracks'] . "
";
// you can add other variables too
$track .= "
";
}
echo $volume;
echo "===================
";
echo $track;
?>