【php】php基本 覚え書き

自分用の覚え書きです

文字列を1文字ずつ配列に入れる

$str = "Hello php";

$hoges = str_split($str);
$hoges2 = str_split($str, 3);//3文字ずつ格納

配列の要素が全部一致しているかどうか

$hoges = [ "a", "a", "ab" ] ;

if(count(array_unique($hoges)) == 1){
 print_r("match!");
}

配列の要素で重複しているものをカウントしたい

$hoges = array("hoge","hoge","foo","foo","hoge","nya");

$count_val = array_count_values($input);
print_r($count_val);

出力結果

Array
(
   [hoge] => 3
   [foo] => 2
   [nya] => 1
)

while文

import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ!!
        
        int i = 10000;
        
        while(true){
            if(i%13==0){
                System.out.println(i);
                break;
            }
            i++;
        }

    }
}
あぶらぼうず

参考元:

https://www.softel.co.jp/blogs/tech/archives/5445

https://lab.syncer.jp/Web/PHP/Snippet/14/
https://note.com/shimakaze_soft/n/n4349e3afdeb3
0

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です