How to use this if condition under echo?

Nisha Atram :

This is normal radio button

<?php
$che='adi';
$che1='adi';
?>

<input type="radio" name="Owner" <?php if($che==$che1) {echo "checked";}?> value="A">A

I want this php code in under echo for checked

<?php
$che='adi';
$che1='adi';

echo'<input type=radio name=ans  value=A>A';?>
Illya :

Try :

echo'<input type=radio name=ans '.(($che == $che1)? "checked" : "").' value=A>A';

Reference :https://davidwalsh.name/php-ternary-examples

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=17917&siteId=1
Recommended