Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Details {
- public $value;
- public function __construct($value) {
- $this->value = $value;
- }
- }
- $details = [new Details(1), new Details(2), new Details(3)];
- $bool = false;
- $obj;
- foreach ($details as $detail) {
- // random if condition
- if ($detail->value == 1) {
- $obj = $detail;
- $bool = true;
- }
- }
- if (!$bool) {
- $obj = new Detail(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement