| 566 | |
| 567 | /** |
| 568 | * Performs a deep copy of an item to ensure that arrays of objects |
| 569 | * are properly duplicated |
| 570 | * |
| 571 | * @param mixed $data The data to be duplicated |
| 572 | * @return mixed copy of the data |
| 573 | */ |
| 574 | public function deep_copy( $data ) { |
| 575 | if ( is_object( $data ) ) { |
| 576 | return clone $data; |
| 577 | } elseif ( is_array( $data ) ) { |
| 578 | $new = array(); |
| 579 | foreach ( $data as $key => $value ) { |
| 580 | if ( is_object( $value ) ) { |
| 581 | $new[ $key ] = clone $value; |
| 582 | } elseif ( is_array( $value ) ) { |
| 583 | $new[ $key ] = $this->deep_copy( $value ); |
| 584 | } else { |
| 585 | $new[ $key ] = $value; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | return $new; |
| 590 | } else { |
| 591 | return $data; |
| 592 | } |
| 593 | } |