Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zambahacker
  5. * Date: 28/07/15
  6. * Time: 21.12
  7. */
  8.  
  9. class CercainArray{
  10. private $array;
  11.  
  12. public function __construct($array){
  13. $this->array = $array;
  14. }
  15.  
  16. public function trovaNum(){
  17. $array = count($this->array) + 1;
  18. $somma = 0;
  19. foreach($this->array as $numero){
  20. $somma += $numero;
  21. }
  22. return (($array*($array+1))/2) - $somma;
  23. }
  24.  
  25. }
  26.  
  27. $array = array(3, 4, 9, 2, 7, 1, 8, 6);
  28.  
  29. $cerca = new CercainArray($array);
  30. echo $cerca->trovaNum();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement