SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to optimise this

    Is there anyway I can optimise this bit of code?

    PHP Code:
    <?php if($data["foo"]):?>
         <option value="0">No</option>
         <option selected="selected" value="1">Yes</option><?php
    else: ?>
         <option selected="selected" value="0">No</option>
         <option value="1">Yes</option><?php
    endif; ?>
    $data["foo"] is always boolean
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can make it a tiny itty bit shorter, but I wouldn't call it more optimized. Overoptimizing reduces the time you can spend making your application do what it does and getting it out the door

    PHP Code:
    <option value="0"<?php if (!$data["foo"]) echo ' selected="selected"'?>>No</option>
    <option value="1"<?php if ($data["foo"]) echo ' selected="selected"'?>>Yes</option>

  3. #3
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers Dan,

    I'm just trying to cut down on those lines of code
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •