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

php?二维数组转一维数组

WBOY
WBOYOriginal
2016-06-20 12:50:09998browse

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


回复讨论(解决方案)

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

$a = array( 'A1', 'A2', 'A3', 'A4', 'A5' );print_r($a);
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);
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 

你说的 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>


这样传统些
<?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>

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

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