我在.net的C#里用这样的代码实现对输入的数据的单双数进行判断,请问同样功能的代码,在PHP里应该怎么去编写?C#代码如下:
String Str_Input = Int_Input.ToString();
bool B_FoundMatch = false;
try
{
B_FoundMatch = Regex.IsMatch(Str_Input, "[13579]$"); //如果B_FoundMatch = true,则为单数,否则,为双数
if (B_FoundMatch)
{
Int_Output = 1; //单数
}
else if (!B_FoundMatch)
{
Int_Output = 2; //双数
}
}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}
String Str_Input = Int_Input.ToString();
bool B_FoundMatch = false;
try
{
B_FoundMatch = Regex.IsMatch(Str_Input, "[13579]$"); //如果B_FoundMatch = true,则为单数,否则,为双数
if (B_FoundMatch)
{
Int_Output = 1; //单数
}
else if (!B_FoundMatch)
{
Int_Output = 2; //双数
}
}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货