Last active
September 10, 2018 00:40
-
-
Save anam-hossain/4dc49fc3b1b1d931cedffdbeb3182b0d to your computer and use it in GitHub Desktop.
Passing by reference from Foreach loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class test | |
{ | |
public function addDescription(&$data) | |
{ | |
$data['description'] = 'Hello World!'; | |
} | |
public function printMessages() | |
{ | |
$messages = [ | |
['code' => 200], | |
['code' => 200], | |
['code' => 200], | |
['code' => 200], | |
]; | |
foreach($messages as &$message) { | |
$this->addDescription($message); | |
} | |
var_dump($messages); | |
} | |
} | |
(new Test())->printMessages(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment