A
A
Abc Edc2015-01-28 19:09:45
Programming
Abc Edc, 2015-01-28 19:09:45

Why are there links in PHP?

I have been actively programming in PHP and JS for a year now, and recently leafing through notebooks from lectures on C ++ every now and then I came across links, as far as I remember this in order for the program to be dynamic or something connected with memory there, in general, there’s nothing I like I remember it can’t do without pointers and links, I decided to take a closer look at the PHP documentation and there is a lot of emphasis on this, why use links and pointers in PHP, how to use it correctly and you can give some example, let’s say how this can help in working with the database or using the example of a controller / models of something everyday for a PHP programmer, it would be very useful for me!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MintTea, 2015-01-28
@gleber1

Well, right off the bat:
Modifying elements inside the loop requires a reference:

foreach ($array as &$item) {
    $item *= 2;
}

Recursive closure is implemented by reference:
$recursiveClosure = function() use (&$recursiveClosure) {
    $recursiveClosure();
};

Passing parameters to a function by reference:
function foo(&$result)
{
    $result = 'result';
}

You can continue. I'm surprised you haven't experienced any of the above in a year.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question