所以我问这个是因为我正在解析一些数据,我把它放在一个叫做“卡片”的数组中。如果我print_r($cards)
我的输出将是这样的:
[0] => The Hunt for Gollum
[1] => (x3)
[2] => The Hunt for Gollum
[3] => (x3)
[4] => The Hunt for Gollum
[5] => (x3)
[6] => The Hunt for Gollum
[7] => (x3)
[8] => The Hunt for Gollum
[9] => (x3)
[10] => The Hunt for Gollum
[11] => (x3)
[12] => The Hunt for Gollum
[13] => (x3)
[14] => The Hunt for Gollum
[15] => (x3)
[16] => The Hunt for Gollum
[17] => (x1)
[18] => The Hunt for Gollum
[19] => (x3)
[20] => The Hunt for Gollum
[21] => (x4)
[22] => The Hunt for Gollum
[23] => (x2/x0)
[24] => The Hunt for Gollum
[25] => (x3)
[26] => The Hunt for Gollum
[27] => (x2)
[28] => The Hunt for Gollum
[29] => (x2)
[30] => The Hunt for Gollum
[31] => (x2)
[32] => The Hunt for Gollum
[33] => (x2/x1)
[34] => The Hunt for Gollum
[35] => (x5/x2)
[36] => The Hunt for Gollum
[37] => (x2)
[38] => The Hunt for Gollum
[39] => (x2)
[40] => The Hunt for Gollum
[41] => (x3/x1)
而我问,如果你知道一种方法,所以我可以显示该阵列这样的:[0]=>The Hunt for Gollum (x3)
,[1]=>The Hunt for Gollum (x3)
等等...但用更少的代码..不reapeating自己[47]
的时间日Thnx
您像这样创建一个新数组:
$array = ["The Hunt for Gollum", "(x2)","The Hunt for Gollum", "(x2)","The Hunt for Gollum", "(x2)"];
$newArray = [];
for( $i=0; $i < count($array) - 1; $i++ ){
$newArray[] = $array[$i]. ' '. $array[$i+1];
$i++;
}
print_r($newArray);
在线试用沙盒在线phpfunctions
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句