Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function free_positions($cua = array(), $first, $last, $MAX){
- $free = 0;
- if($first < $last){
- if($first != 1){ // Significa que hay huecos desde el principio
- $free = $free + ($first - 1);
- }
- if($last != 1){ // Significa que hay huecos desde hasta el final
- $free = $free + ($MAX - $last);
- }
- } else {
- $free = $first - $last - 1;
- }
- return $free;
- }
- $MAX = 10;
- $cua = array(
- 1 => '',
- 2 => '',
- 3 => 'ocupat',
- 4 => 'ocupat',
- 5 => 'ocupat',
- 6 => '',
- 7 => '',
- 8 => '',
- 9 => '',
- 10 => ''
- );
- $first = 3;
- $last = 5;
- echo free_positions($cua, $first, $last, $MAX);
- $MAX = 10;
- $cua = array(
- 1 => 'ocupat',
- 2 => 'ocupat',
- 3 => '',
- 4 => '',
- 5 => '',
- 6 => '',
- 7 => '',
- 8 => 'ocupat',
- 9 => 'ocupat',
- 10 => 'ocupat'
- );
- $first = 8;
- $last = 2;
- echo free_positions($cua, $first, $last, $MAX);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement