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.

【PHP】よく使う比較分、デバッグコード 等

Posted at

最近、PHPのコードも書く事が増えてきて、
脳内ではやりたい事は決まってるんだけど、PHPだとどう書くんだったっけ?みたいなのを列挙。
見ればすぐに、思い出す系のやつです。

定数定義

define("SYSTEM_NAME","hogehogeシステム");

変数定義

$i = 0;
$val = "moji";
$flag = false;
$data = SYSTEM_NAME;

数値比較

これは、他の言語と変わらない。
if($i > 0){ }

文字比較

if(strcmp("もじA","もじB") == 0){ //一致した場合 }

##文字連結
他の言語だと「+」とか「&」
$buff = $buff.$key.",".$name."end";

##文字分割
他の言語だと「split」とか
カンマごとに分割する例
$params = explode(",", $row);

##連想配列
$result = array(); $result["key"] = "value";

##ループ
for ($i = 0; $i < count($data); $i++) { $row = $data[$i]; }

連想配列の時とか
foreach ($result as $key => $value) { $item = $result[$key]; }

##function
function getValue($key){ return "value"; }

##コンソール出力
文字出力
echo "出力";
変数出力
var_dump($val);

##お約束

「?>」は、最後までPHPのコード(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?