<?php
/**
* @assert ('文字列です。') === true
* @assert ('abcd1234+:;!') === false
* @assert ('全角abcd') === false
* @assert ('半角カナ') === false
*/
function is_zen_preg_match ($str) {
if (!preg_match("/(?:\xEF\xBD[\xA1-\xBF]|\xEF\xBE[\x80-\x9F])|[\x20-\x7E]/", $str)) {
return true;
} else {
return false;
}
}
<?php
class Checker {
function check_name($value) {
return false;
}
}
$profile = array(
'name' => 'my name',
'phone' => '333-3333-3333'
);
$checker = new Checker();
function check($checker, $key, $value ){
$method = "check_$key";
if(method_exists($checker, $method)){
return $checker->$method($value);
}
return true;
}
foreach($profile as $key => $value ){
echo $key, ":", check($checker, $key, $value ), "\n";
}
<?php
$array = array('a' => 1, 'b' => 2, 'c' => 3);
$array2 = array_map(function($val){ return $val * 2 ; }, $array);
foreach($array as $k => $v ){
echo "$k .... $v\n";
}
foreach($array2 as $k => $v ){
echo "$k .... $v\n";
}
$ php tests_map.php
a .... 1
b .... 2
c .... 3
a .... 2
b .... 4
c .... 6
$model_class = get_class($instance);
$value = $model_class::$static_value;
unset($array[$i]);
-接続確認
# /vagrant/php/vendor/bin/psysh
Psy Shell v0.5.2 (PHP 5.5.27 ― cli) by Justin Hileman
>>> (new mysqli('localhost', 'root', 'password'))->query('show databases')->fetch_all();
- php.ini
display_errors = on
error_reporting = E_ALL
データベース