Jump to content

Search the Community

Showing results for tags '? and : operators'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. This script is an exercise that i got from a text book. It simulates the path of a homing pigeon as it flies from its starting point to its home. The script is easy to comprehend. The only problem i have is the block of code that displays the map as I've highlighted below. <?php $mapsize = 10; // Position the home and the pigeon do{ $homeX = rand (0, $mapsize-1); $homeY = rand (0, $mapsize-1); $pigeonX = rand(0, $mapsize-1); $pigeonY = rand(0, $mapsize-1); } while ((abs($homeX-$pigeonX) < $mapsize/2) && (abs($homeY-$pigeonY) < $mapsize/2)); do{ // Move the pigeon closer to home if ($pigeonX < $homeX) $pigeonX++; elseif ($pigeonX > $homeX) $pigeonX--; if ($pigeonY < $homeY) $pigeonY++; elseif ($pigeonY > $homeY) $pigeonY--; // Display the current map echo '<div class="map" style="width: ' . $mapsize . 'em;"><pre>'; for ($y = 0; $y < $mapsize; $y++){ for ($x = 0; $x < $mapsize; $x++){ if ($x == $homeX AND $y == $homeY){ echo '<span class ="home">+</span>'; // Home } elseif ($x == $pigeonX && $y == $pigeonY) { echo '<span class ="pigeon">%</span>'; // Pigeon } else { echo '<span class = "empty">.</span>'; //Empty square } echo ($x != $mapsize - 1) ? " " : " "; } echo "\n"; } echo "</pre></div>\n"; } while ($pigeonX != $homeX || $pigeonY != $homeY); ?> </body> </html> How does this line affect the map? I have never come across the "?" and ":" operators, moreover the use of echo in this fashion. echo ($x != $mapsize - 1) ? " " : " ";
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.