多个数组转换成字符串,该怎么处理

WBOY
Release: 2016-06-13 11:13:09
Original
1067 people have browsed it

多个数组转换成字符串

本帖最后由 mail163lc 于 2013-01-25 11:55:19 编辑 数组
<br />$a=Array ( [0] => 1 [1] => 2 ) <br />$b=Array ( [0] => 1 [1] => 2 ) <br />$c=Array ( [0] => 128 [1] => 108 ) <br />$d=Array ( [0] => 128 [1] => 216 )<br />
Copy after login



需要转化成的字符串
$e=1|1|128|128|~2|2|108|216

数组可能还会加
<br />$a=Array ( [0] => 1 [1] => 2 [2] => 3 ) <br />$b=Array ( [0] => 1 [1] => 2 [2] => 2 ) <br />$c=Array ( [0] => 128 [1] => 108 [2] => 420 ) <br />$d=Array ( [0] => 128 [1] => 216 [2] => 840 )<br />
Copy after login


转换的结果就需要编程
$e=1|1|128|128|~2|2|108|216|~3|2|420|840


------解决方案--------------------
$a = Array ( 0 => 1, 1 => 2, 2 => 3 );<br />$b = Array ( 0 => 1, 1 => 2, 2 => 2 );<br />$c = Array ( 0 => 128, 1 => 108, 2 => 420 );<br />$d = Array ( 0 => 128, 1 => 216, 2 => 840 );<br /><br />echo foo($a, $b, $c, $d);<br /><br />function foo() {<br />  foreach(func_get_args() as $t) {<br />    foreach($t as $i=>$v)<br />      $r[$i][] = $v;<br />  }<br />  foreach($r as $i=>$v)<br />    $r[$i] = join('<br><font color='#FF8000'>------解决方案--------------------</font><br>', $v);<br />  return join('<br><font color='#FF8000'>------解决方案--------------------</font><br>~', $r);<br />}<br />
Copy after login
1
------解决方案--------------------
1
------解决方案--------------------
128
------解决方案--------------------
128
------解决方案--------------------
~2
------解决方案--------------------
2
------解决方案--------------------
108
------解决方案--------------------
216
------解决方案--------------------
~3
------解决方案--------------------
2
------解决方案--------------------
420
------解决方案--------------------
840
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