LoginSignup
1
0

More than 5 years have passed since last update.

PHPの挙動メモ

Last updated at Posted at 2016-06-22

自分用で、挙動確認とかしたやつのメモ。

array_intersect

https://3v4l.org/8ig5r

<?php
$a = [1,2,2,3,3,3,4,4,4,4];
$b = [2,3,5];

var_dump(
    array_intersect($a, $b), // [2,2,3,3,3] 
    array_intersect($b, $a)  // [2,3]
);

filter_

<?php
var_dump(filter_var_array(
    ['a' => 0],
    [
        'a' => [
            'filter' => FILTER_VALIDATE_INT,
            'options' => [
                'default' => 1,
                'min_range' => 1
            ],
        ],
        'b' => [
            'filter' => FILTER_VALIDATE_INT,
            'options' => [
                'default' => 0,
                'min_range' => 0,
            ],
        ],
    ]
));
/*
array(2) {
  ["a"]=>
  int(1)
  ["b"]=>
  NULL
}
*/

if文の式が、代入の式

https://3v4l.org/v4TYG

<?php

if ($t = true) { // 入る
    echo 'true assignment '.PHP_EOL;
}
if ($f = false) {
    echo 'false assignment'.PHP_EOL;
}
if ($zeroString = '0') {
    echo 'string "0" letter '.PHP_EOL;
}
if ($zeroAStringCastToInt = (int)'0a') {
    echo 'cast to int witch string "0a"'.PHP_EOL;
}
if ($zeroA = '0a') { // 入る
    echo 'string "0a" letters'.PHP_EOL;
}
if ($oneAStringCastToInt = (int)'1a') { // 入る
    echo 'cast to int witch string "1a"'.PHP_EOL;
}
1
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
1
0