これがOPの質問に答えないことは知っていますが、このページは複数の針を持つstrposのGoogleのトップにあるため、コメントしたかった. これを行うための簡単な解決策があります(繰り返しますが、これはOPの質問に固有のものではありません-申し訳ありません):
$img_formats = array('.jpg','.png');
$missing = array();
foreach ( $img_formats as $format )
if ( stripos($post['timer_background_image'], $format) === false ) $missing[] = $format;
if (count($missing) == 2)
return array("save_data"=>$post,"error"=>array("message"=>"The background image must be in a .jpg or .png format.","field"=>"timer_background_image"));
$missing 配列に 2 つの項目が追加された場合、入力が $img_formats 配列のどの画像フォーマットも満たしていないことを意味します。その時点で、エラーなどを返すことができることがわかります。これは簡単に小さな関数に変換できます。
function m_stripos( $haystack = null, $needles = array() ){
//return early if missing arguments
if ( !$needles || !$haystack ) return false;
// create an array to evaluate at the end
$missing = array();
//Loop through needles array, and add to $missing array if not satisfied
foreach ( $needles as $needle )
if ( stripos($haystack, $needle) === false ) $missing[] = $needle;
//If the count of $missing and $needles is equal, we know there were no matches, return false..
if (count($missing) == count($needles)) return false;
//If we're here, be happy, return true...
return true;
}
代わりに then 関数を使用した最初の例に戻ります。
$needles = array('.jpg','.png');
if ( !m_strpos( $post['timer_background_image'], $needles ) )
return array("save_data"=>$post,"error"=>array("message"=>"The background image must be in a .jpg or .png format.","field"=>"timer_background_image"));
もちろん、関数が true または false を返した後に何をするかはあなた次第です。