Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. <?php
  2.  
  3. class Details {
  4.     public $value;
  5.     public function __construct($value) {
  6.         $this->value = $value;
  7.     }
  8. }
  9.  
  10. $details = [new Details(1), new Details(2), new Details(3)];
  11.  
  12. $bool = false;
  13. $obj;
  14. foreach ($details as $detail) {
  15.     // random if condition
  16.     if ($detail->value == 1) {
  17.         $obj = $detail;
  18.         $bool = true;
  19.     }
  20. }
  21.  
  22. if (!$bool) {
  23.     $obj = new Detail(1);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement