$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています
$split_arr = preg_split('/[ ;;,,、\n\t]+/ui', ' ' . $str); var_dump($split_arr);
array(7) { [0] => string(0) "" [1] => string(6) "午前" [2] => string(6) "午後" [3] => string(3) "昼" [4] => " [5] => " [6] => string(6) "学習" }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" );
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $out_arr = array(); foreach($a as $k =>$var ) { if( $k == "key_3" || $k == "key_4" || $k == "key_5" ) { $out_arr[$k] = $var ; }
$a = array( "key_0" => "val 0", "key_1" => "val one", "key_2" => "val two", "key_3" => "val three", "key_4" => "val four", "key_5" => "val five", "key_6" => "val six" ); $array_keys = array_keys($a); $matched_keys = array_filter( $array_keys, function($k){ return preg_match( "/key_[2-4]/u" , $k) ;} ); foreach($matched_keys as $key){ echo $a[$key]."\n" ; }
array_filter関数の2番目の引数がコールバック関数なので、このコールバック関数に正規表現で特定なキーのマッチングを行っています