PHP和JavaScrip分别获取关联数组的键值示例代码

前端之家收集整理的这篇文章主要介绍了PHP和JavaScrip分别获取关联数组的键值示例代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

PHP版:
<div class="codetitle"><a style="CURSOR: pointer" data="95644" class="copybut" id="copybut95644" onclick="doCopy('code95644')"> 代码如下:

<div class="codebody" id="code95644">
$o = array('x'=>1,'y'=>2,'z'=>3);
$arr = array();
$i = 0;
foreach( $o as $arr[$i++]=>$v )/empty/;
var_dump($arr); //$arr = array('x','y','z');

JavaScrip版:
<div class="codetitle"><a style="CURSOR: pointer" data="87358" class="copybut" id="copybut87358" onclick="doCopy('code87358')"> 代码如下:
<div class="codebody" id="code87358">
var o = {x:1,y:2,z:3};
var arr = [],i = 0;
for ( arr[i++] in o ) /empty/ ;
console.log( arr ); //arr = ['x','z'];

猜你在找的PHP相关文章