Jump to content

Search the Community

Showing results for tags 'for loop'.



More search options

  • 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 (Dreamweaver, Zend, 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. There are seats that need to be assigned to visitors, for each visitor I check if the seat is available, if it is, give the value 'x' for 1 $visitor until there are no visitors left. I want to execute a line of code for x times, x = the value of visitors. As the code is now, I want to suggest 2 visitors a seat by giving the value 'x'. I will use the values as follows: 1 = available 0 = is not available x = was available, and now it's a suggested seat The problem: I want to have a output of two X's, but as the script is now, it generates three X's, and I don't know why. The question: How do make my script so that it will output two X's (the value of $visitors)? The output: Visitors: 2 Array ( [0] => Array ( [seatAvailable] => 0 [seatNumber] => 1 ) [1] => Array ( [seatAvailable] => 0 [seatNumber] => 2 ) [2] => Array ( [seatAvailable] => x [seatNumber] => 3 ) [3] => Array ( [seatAvailable] => x [seatNumber] => 4 ) [4] => Array ( [seatAvailable] => x [seatNumber] => 5 ) ) My code <?php $visitors = 2; $seats = array( array( 'seatAvailable' => '0', 'seatNumber' => '1' ), array( 'seatAvailable' => '0', 'seatNumber' => '2' ), array( 'seatAvailable' => '1', 'seatNumber' => '3' ), array( 'seatAvailable' => '1', 'seatNumber' => '4' ), array( 'seatAvailable' => '1', 'seatNumber' => '5' ), ); echo "Visitors: ".$visitors; echo "<ol>"; foreach($seats as &$val){ //If not available if($val['seatAvailable'] == '0'){ //echo "<li>not available</li>"; } //If available elseif($val['seatAvailable'] == '1'){ //Give available spots the value X, for as many as there are $visitors for($i=0;$i<$visitors;$i++){ $val['seatAvailable'] = 'x'; } } } echo "</ol>"; echo "<pre>"; print_r($seats); echo "</pre>"; ?>
×

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.