string(3) "1:6"   [2]=>   string(3)&"/>   string(3) "1:6"   [2]=>   string(3)&">
Home > Backend Development > PHP Tutorial > 请问一个数据格式转换

请问一个数据格式转换

WBOY
Release: 2016-06-13 12:59:59
Original
917 people have browsed it

请教一个数据格式转换

<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 />
Copy after login

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

------解决方案--------------------
$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);
Copy after login
Array
(
    [0] => 3
    [1] => 6
    [2] => 9
    [3] => 2
    [4] => 4
)

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template