inul php id,循環遍歷數組,在PHP中使用類似的項目。

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;

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值