Saturday 3 August 2019

php - Whit what is yeild different from echo

What is the difference between them and this two examples:



function result($r){
for($i=0; $i<$r; $i++){
yield $i;
}
}

foreach(result(15) as $r){

echo $r;
};


And one with echo only:



function result($r){
for($i=0; $i<$r; $i++){
echo $i;
}

}

result(15);


I am sure there is some but what is it? Couldn't answer myself after some googling, sorry.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...