Home > Backend Development > PHP Tutorial > php?二维数组转一维数组

php?二维数组转一维数组

WBOY
Release: 2016-06-20 12:50:09
Original
1009 people have browsed it

Array ( [0] => A1 [1] => A2 [2] => A3 [3] => A4 [4] => A5 ) 如何将这个数组转化为Array(A1,A2,A3,A4,A5)
Copy after login


回复讨论(解决方案)

他就是 Array(A1,A2,A3,A4,A5)

$a = array( 'A1', 'A2', 'A3', 'A4', 'A5' );print_r($a);
Copy after login
Copy after login
Array ( [0] => A1 [1] => A2 [2] => A3 [3] => A4 [4] => A5 )

他就是 Array(A1,A2,A3,A4,A5)

$a = array( 'A1', 'A2', 'A3', 'A4', 'A5' );print_r($a);
Copy after login
Copy after login
Array ( [0] => A1 [1] => A2 [2] => A3 [3] => A4 [4] => A5 )


for(var i=0;i<a.length;i++){                   alert(a[i]);                }循环出来的是 a  r  r  a  y 
Copy after login

你说的 Array(A1,A2,A3,A4,A5) 是 js 的数组?
是的话,你总得说清楚啊!

<?php$a = array( 'A1', 'A2', 'A3', 'A4', 'A5' );?><script>var a = <?php echo json_encode($a); ?>;for(var i=0;i<a.length;i++){  alert(a[i]);}</script>
Copy after login


这样传统些
<?php$a = array( 'A1', 'A2', 'A3', 'A4', 'A5' );?><script>var a = Array("<?php echo join('", "', $a); ?>");for(var i=0;i<a.length;i++){  alert(a[i]);}</script>
Copy after login

你那个是php的数组格式,你的应用场景是什么?Ajax 请求php返回数组吗?

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