Home >Backend Development >PHP Tutorial >PHP和JavaScrip分别获取关联数组的键值示例代码_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:03:48841browse

PHP版:
复制代码 代码如下:
$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版:
复制代码 代码如下:
var o = {x:1, y:2, z:3};
var arr = [], i = 0;
for ( arr[i++] in o ) /*empty*/ ;
console.log( arr ); //arr = ['x', 'y', 'z'];

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