Dirk van der Burgt Dirk van der Burgt - 1 year ago 100
PHP Question

Converting if else statement from javascript to php

In javascript my if else statement goes like this:

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:

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

I have no idea how to convert x.length to a php variable. 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. Because this code will be a part of a bigger project.

Answer Source

You can use below syntax for checking that variable is having value or not.

if (null != $varx && null != $vary) {
    // your code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download