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

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

请问一个数据格式转换

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

请教一个数据格式转换

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

转换成
<br />array(5) {<br />  0=>3,<br />  1=>6,<br />  2=>9,<br />  3=>2,<br />  4=>4<br />}<br /><br />

------解决方案--------------------
$ar = array('0:3', '1:6', '2:9', '3:2', '4:4');<br /><br />foreach($ar as $v) {<br />  $t = explode(':', $v);<br />  $res[$t[0]] = $t[1];<br />}<br /><br />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