Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

PHP - if, else, elseif condition

0 votes
33 views
added Mar 27 in PHP by LC Marshal First Warrant Officer (8,170 points)
edited Apr 20 by LC Marshal

If $bedrooms is not empty, show the .hidden-t-m elements

<?php if (!empty($bedrooms)): ?>
    <div class="hidden-t-m"><?php print $bedrooms ?> Beds</div> 
<?php endif; ?>

9 examples

0 votes
responded Apr 16 by LC Marshal First Warrant Officer (8,170 points)
edited Apr 20 by LC Marshal

If value has no character or null

<?php if ($row['authname']==0): ?>
    <span class="show-anon">Anonymous</span>
<?php endif; ?>
0 votes
responded Apr 18 by LC Marshal First Warrant Officer (8,170 points)
edited Apr 20 by LC Marshal

If value is not null

<?php if (!empty($title)): ?>
    <h1 class="page-header"><?php print $title; ?></h1>
<?php endif; ?>
0 votes
responded Apr 20 by LC Marshal First Warrant Officer (8,170 points)

If empty

<?php if (empty($row['name'])): ?>
    Anonymous
<?php endif; ?>
0 votes
responded Apr 24 by LC Marshal First Warrant Officer (8,170 points)

Check if value is exist

<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Got Irix";
}
if (in_array("mac", $os)) {
    echo "Got mac";
}
?>
0 votes
responded Apr 24 by LC Marshal First Warrant Officer (8,170 points)

If value available only rental and room_rental, show Rent, else show  $specific_type = $field_prop_listing_type

<?php
  if ( ($field_prop_listing_type == 'rental') ||  ($field_prop_listing_type == 'room_rental') )
  {
    $specific_type = "Rent";
  }
  else
  $specific_type = $field_prop_listing_type;
  ?>
  <?php print 'For ' . $specific_type; 
?>
0 votes
responded Apr 24 by LC Marshal First Warrant Officer (8,170 points)

Condition for time 

<?php
$t = date("H");

if ($t < "10") {
    echo "Have a good morning!";
} elseif ($t < "20") {
    echo "Have a good day!";
} else {
    echo "Have a good night!";
}
?>
0 votes
responded Apr 24 by LC Marshal First Warrant Officer (8,170 points)
Condition over condition
<div class="extended-stats hidden-m">
    <?php if (!empty($la_ppu)):?>
     <?php print 'RM ' . $la_ppu . ' psf';?>
   <?php else:?>
     <?php if ($node->field_prop_listing_type->und[0]->value !== 'rental'): ?>
       <span class="est-mort"> 
          <span class="value"></span>/mth
        </span>
      <?php endif; ?>   
    <?php endif;?>
</div>
0 votes
responded Apr 24 by LC Marshal First Warrant Officer (8,170 points)
Hide if value !== 'thisValue"
<?php if ($node->field_prop_listing_type->und[0]->value !== 'rental'):?>
<div class="calculator" onclick="jQuery('.mortgage-calculator').toggleClass('hidden')">
    <i class="fa fa-calculator" aria-hidden="true"></i>
    <i class="fa fa-angle-down" aria-hidden="true"></i>
</div>
<?php endif;?>
0 votes
responded May 3 by LC Marshal First Warrant Officer (8,170 points)

If user is login, show this. Else show this

<div class="search-box-area">
  <h2>Got A Property Question? Get Answers Here, or</h2>
  <?php if(isset($user->roles[1]) ) { ?>
  <div id="forum-ask-btn-sign-in"><a class="btn btn-xs btn-success" href="?showlogin=true">Sign In to Ask a Question</a></div> 
  <?php } else { ?>
  <div id="forum-ask-btn"></div>
  <?php } ?>
</div>
lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...