简体   繁体   English

真的很简单 PHP strlen/if 问题

[英]Really simple PHP strlen/if question

I am trying to take 2 strings, see what length they are, and if one is larger than the other, set it as $phonenumber , and the other as $extension .我正在尝试使用 2 个字符串,查看它们的长度,如果一个大于另一个,则将其设置为$phonenumber ,将另一个设置为$extension See below:见下文:

if(strlen($temp_ext) > 4)
{
    $extension = $temp_cid;
    $phonenumber = $temp_ext;
}
else
{
    $extension = $temp_ext;
    $phonenumber = $temp_cid;
}

This doesn't look like it works, though.不过,这看起来行不通。 I am still getting 10 digit numbers in extension, and 4 digit numbers in the $phonenumber variable.我仍然在分机中获得 10 位数字,在$phonenumber变量中获得 4 位数字。 What am I missing?我错过了什么?

Try this尝试这个

if(strlen($temp_ext) > strlen($temp_cid))
{
    $extension = $temp_cid;
    $phonenumber = $temp_ext;
}
else
{
    $extension = $temp_ext;
    $phonenumber = $temp_cid;
}

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM