PHP and JavaScript respectively obtain the key values ​​​​of associative arrays sample code_PHP tutorial

WBOY
Release: 2016-07-21 16:12:45
Original
813 people have browsed it

PHP version:

Copy code The code is as follows:

$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');

JavaScript version:
Copy code The code is as follows:

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'];

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313623.htmlTechArticlePHP version: Copy the code as follows: $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');...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!