Câu hỏi phỏng vấn PHP
Câu hỏi

What does yiel...

Câu trả lời

What does yield mean in PHP?

In PHP, the yield keyword is used in the context of generators. Generators are a special type of function that can be paused and resumed, allowing them to generate a sequence of values without the need to create and store the entire sequence in memory at once.

When a generator function encounters the yield keyword, it temporarily suspends its execution and returns the yielded value to the caller. The next time the generator is called, it resumes execution from where it left off, continuing until it encounters the next yield statement or reaches the end of the function.

Here's an example of a simple generator function in PHP:

php Copy
function generateNumbers() {
    yield 1;
    yield 2;
    yield 3;
}

$numberGenerator = generateNumbers();

echo $numberGenerator->cur...
senior

senior

Gợi ý câu hỏi phỏng vấn

entry

What is the return type of a function that doesn't return anything?

senior

What is the best method to merge two PHP objects?

senior

Explain the Exception Hierarchy introduced in PHP7

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào