简体   繁体   English

将if else语句从javascript转换为php

[英]Converting if else statement from javascript to php

In javascript my if else statement goes like this: 在javascript中我的if else语句是这样的:

var x = document.getElementById('input1').value;
var y = document.getElementById('input2').value;
if (x.length > 0 && y.length > 0) {
    //execute code
}

This is what I have soo far with php: 这就是我对php的远见:

$varx = $_POST['input1'];
$vary = $_POST['input2'];
if () {
    //execute code
}

I have no idea how to convert x.length to a php variable. 我不知道如何将x.length转换为php变量。 It would help me alot if someone knows how to do this. 如果有人知道如何做到这一点,这将有助于我。

I really want to have the if else statement in php so please don't come up with other solutions because I'll get even more confused. 我真的想在php中使用if else语句,所以请不要提出其他解决方案,因为我会更加困惑。 Because this code will be a part of a bigger project. 因为这段代码将成为更大项目的一部分。

You can use below syntax for checking that variable is having value or not. 您可以使用以下语法来检查变量是否具有值。

if (null != $varx && null != $vary) {
    // your code
}

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

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