함수 list()


1 JavaScript[ | ]

var arr = ['coffee', 'brown', 'caffeine'];
drink = arr[0];
color = arr[1];
power = arr[2];
console.log(drink); // coffee
console.log(color); // brown
console.log(power); // caffeine
function list(v,a) { for(var i=0;i<a.length; i++) (this)[v[i]] = a[i]; }

var arr = ['coffee', 'brown', 'caffeine'];
list(['drink','color','power'], arr);
console.log(drink); // coffee
console.log(color); // brown
console.log(power); // caffeine

2 PHP[ | ]

$arr = array('coffee', 'brown', 'caffeine');
list($drink, $color, $power) = $arr;
echo $drink; // coffee
echo $color; // brown
echo $power; // caffeine

3 Perl[ | ]

my @arr = ('coffee', 'brown', 'caffeine');
my ($drink, $color, $power) = @arr;
print $drink . "\n"; # coffee
print $color . "\n"; # brown
print $power . "\n"; # caffeine
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}