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?

PHPで「foreach文」の動作を確認してみた。

Last updated at Posted at 2025-03-17

概要

PHPで「foreach文」の動作を確認してみました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

sample.php
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>PHPテスト</title>
</head>
<body>

<p>PHPのテストです。</p>

<p>
<?php
$preflist = array('東京', '大阪', '名古屋');

foreach ($preflist as $pref){
  print $pref.'<br />';
}
?>
</p>

</body>
</html>

以下のコマンドを実行しました。

$ php sample.php 
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>PHPテスト</title>
</head>
<body>

<p>PHPのテストです。</p>

<p>
東京<br />大阪<br />名古屋<br /></p>

</body>
</html>

以下のファイルを作成しました。

sample.php
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>PHPテスト</title>
</head>
<body>

<p>PHPのテストです。</p>

<p>
<?php
$preflist = array('New York', 'Los Angeles', 'Honolulu');

foreach ($preflist as $pref){
  print $pref.'<br />';
}
?>
</p>

</body>
</html>

以下のコマンドを実行しました。

$ php sample.php 
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>PHPテスト</title>
</head>
<body>

<p>PHPのテストです。</p>

<p>
New York<br />Los Angeles<br />Honolulu<br /></p>

</body>
</html>

# まとめ

何かの役に立てばと。
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?