1
1

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.

配列の中身を確認する方法

Posted at

配列の中身は、関数を使うことによってブラウザに表示できます。
関数はvar_dump,print_r,var_exportの3種類があります。
それぞれの違いは下記の通りです。

###1.var_dump($変数名);
・変数の中身の値と型を表示。
・数値型→int(数値) 文字型→string(バイト数)

<?php
 $data = ["tori", "sakana", "niwatori"];
 var_dump($data);
?>
↓
array(3) {
 [0]=>
 string(4) "tori"
 [1]=>
 string(6) "sakana"
 [2]=>
 string(8) "niwatori"
}

###2. print_r($変数名);
・変数の中身の値のみ表示。

<?php
 $data = ["tori", "sakana", "niwatori"];
 print_r($data);
?>
↓
Array
(
 [0] => tori
 [1] => sakana
 [2] => niwatori
)

###3. var_export($変数名);
・変数の中身の値をPHPのソースコードで表示。

<?php
 $data = ["tori", "sakana", "niwatori"];
 var_export($data);
?>
↓

array (
 0 => 'tori',
 1 => 'sakana',
 2 => 'niwatori',
)

参考元はこちら(https://techacademy.jp/magazine/22756)

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?