string(3) "1:6"  [2]=>  string(3) "2"/>   string(3) "1:6"  [2]=>  string(3) "2">

Home  >  Article  >  Backend Development  >  请问一个数据格式转换

请问一个数据格式转换

WBOY
WBOYOriginal
2016-06-13 11:07:01753browse

请教一个数据格式转换


array(5) {
[0]=>
string(3) "0:3"
[1]=>
string(3) "1:6"
[2]=>
string(3) "2:9"
[3]=>
string(3) "3:2"
[4]=>
string(3) "4:4"
}

转换成

array(5) {
0=>3,
1=>6,
2=>9,
3=>2,
4=>4
}


------解决方案--------------------
$ar = array('0:3', '1:6', '2:9', '3:2', '4:4');

foreach($ar as $v) {
$t = explode(':', $v);
$res[$t[0]] = $t[1];
}

print_r($res);
Array
(
    [0] => 3
    [1] => 6
    [2] => 9
    [3] => 2
    [4] => 4
)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn