Skip to Main Content
PHPクックブック ―モダンPHPによるWebアプリケーション実用レシピ集
book

PHPクックブック ―モダンPHPによるWebアプリケーション実用レシピ集

by Eric A. Mann, 廣川 類, 桑村 潤
March 2024
Intermediate to advanced content levelIntermediate to advanced
408 pages
5h 16m
Japanese
O'Reilly Japan, Inc.
Content preview from PHPクックブック ―モダンPHPによるWebアプリケーション実用レシピ集

3章関数

あらゆる言語で書かれたすべてのプログラムは、ビジネスロジックのさまざまな要素を1つに結合することにより構築されます。これらの要素の多くは、アプリケーション内の複数の場所で参照されるため、共通の機能をカプセル化して再利用可能にしておきます。これらの要素をモジュール化して再利用可能にする最も簡単な方法は、そこに含まれているビジネスロジックを関数(そのアプリケーション内のどこからでも参照できる特定の構成要素)にしてカプセル化することです。

文字列の先頭文字を大文字にする簡単なプログラムを例3-1に示します。このような関数を使わないプログラミングは命令型と呼ばれ、コマンド単位(コード行単位)で実行に必要なことを正確に定義します。

例3-1 命令型(関数を使用しない)による文字列の先頭大文字化

$str = "this is an example"; if (ord($str[0]) >= 97 && ord($str[0]) <= 122) { $str[0] = chr(ord($str[0]) - 32); } echo $str . PHP_EOL; // This is an example $str = "and this is another"; if (ord($str[0]) >= 97 && ord($str[0]) <= 122) { $str[0] = chr(ord($str[0]) - 32); } echo $str . PHP_EOL; // And this is another $str = "3 examples in total"; if (ord($str[0]) >= 97 && ord($str[0]) <= 122) { $str[0] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

初めてのGo言語 ―他言語プログラマーのためのイディオマティックGo実践ガイド

初めてのGo言語 ―他言語プログラマーのためのイディオマティックGo実践ガイド

Jon Bodner, 武舎 広幸
Python機械学習クックブック 第2版

Python機械学習クックブック 第2版

Kyle Gallatin, Chris Albon, 中田 秀基
エンジニアが学ぶ会計システムの「知識」と「技術」

エンジニアが学ぶ会計システムの「知識」と「技術」

広川 敬祐, 五島 伸二, 小田 恭彦, 大塚 晃, 川勝 健司

Publisher Resources

ISBN: 9784814400621Publisher Website