我正在使用PHP lang处理数组。我通过旋转for循环获得了以下输出。 现在想把它分成两个不同的数组。任何一个请指导我分成两个不同的数组...喜欢分为[0] = 810和b [0] = 44
以及,我试图在不改变值的情况下对其进行排序,例如排序最大值a [0] = 840& b [0] = 87
Array ( [0] => 810/44 [1] => 0/280 [2] => 73/279 [3] => 0/278 [4] => 0/277 [5] => 0/276 [6] => 840/87 [7] => 0/275 [8] => 0/274 [9] => 0/273 [10] => 6/271 [11] => 0/272 [12] => 0/269 [13] => 3/267 [14] => 0/268 [15] => 3/259 [16] => 124/108 [17] => 82/239 [18] => 221/238 [19] => 30/160 [20] => 3/161 [21] => 65/168 [22] => 73/169 [23] => 0/170 [24] => 0/248 [25] => 192/226 [26] => 209/222 [27] => 80/223 [28] => 273/182 [29] => 79/183 [30] => 73/184 [31] => 73/185 [32] => 6/186 [33] => 73/187 [34] => 0/188 [35] => 48/270 [36] => 138/190 [37] => 370/191 [38] => 152/192 [39] => 12/200 [40] => 200/210 [41] => 0/213 [42] => 21/212 [43] => 124/214 [44] => 0/215 [45] => 0/216 [46] => 133/217 [47] => 6/260 [48] => 73/285 [49] => 73/284 [50] => 0/283 [51] => 73/286 [52] => 73/287 [53] => 0/288 [54] => 73/289 [55] => 0/290 [56] => 76/291 [57] => 76/292 [58] => 0/293 [59] => 0/294 [60] => 0/295 [61] => 0/296 [62] => 0/297 [63] => 3/298 [64] => 0/299 [65] => 0/300 [66] => 3/301 )
答案 0 :(得分:5)
怎么样:
$a = $b = array();
foreach ($array as $key => $value) {
list($a[$key], $b[$key]) = explode('/', $value, 2);
}
编辑:要在之后处理排序,您可以使用:
array_multisort($a, SORT_DESC, SORT_NUMERIC, $b);
答案 1 :(得分:1)
foreach($array1 as $a){
$a = (string)$a
$pos = strpos($a, '/')
$first[] = substr($a, 0, $pos);
$second[] = substr($a, $pos);
}
未经测试。 。但是你可以尝试这些方面的东西
答案 2 :(得分:1)
你可以这样做:
<?php
$a = array();
$b = array();
$orig_array = array('810/44','0/280');
foreach($orig_array as $orig){
$values = explode('/',$orig,2);
$a[]=$values[0];
$b[]=$values[1];
}
print_r($a);
print_r($b);
/*
Array
(
[0] => 810
[1] => 0
)
Array
(
[0] => 44
[1] => 280
)
*/
?>