0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

配列を繰り返して取り出す処理が言語によって微妙に違う…

Last updated at Posted at 2020-11-23

for文で配列を1つづつ取り出して変数に代入したいことってよくありますよね。
色々な言語による微妙な違いで脳がやられます。ここではPython,JavaScript,PHPを取り上げます。


Pythonだと


for(変数 in 配列)
    #繰り返したい処理

inなんですよね。そしてPythonは{}なしでインデントで表します。

でみんな大好きJSだと

//配列のとき
for(変数 of 配列){
    //繰り返したい処理
}

ofなんですよね。ちなみにオブジェクトだとinを使います。

で、PHPだと

foreach($配列 as $変数){
    //繰り返したい処理
}

for文ではなくforeach使ってしかもasです。

混同しそうです………

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?