Dirk van der Burgt Dirk van der Burgt - 2 months ago 6
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.


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

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