How to use the pointer concept in php?

Posted on

Question :

I’m learning about pointer in C language and I already know how to use it. I think the way to use pointer in php is the same in C. But how do I make pointer declaration in php?


Answer :

In PHP it can be called both pointers and references.

References, in PHP, means accessing the same variable content across multiple names. But it is common to misunderstand the expression “use of pointers” in PHP, which in turn does not even look like the pointers in C: we have in PHP nicknames in a symbolic table (in C memory address). >

  $a = &$b;
  // aqui $a e $b apontam para a mesma variável. 


So $ a and $ b are completely the same here, but not because $ a is pointing to $ b or vice versa, but rather because $ a and $ b point to the same place.


The same syntax can be used with functions that return references and with the new operator (from PHP 4.0.4):


Source: link

You can access the original POST on the Live Linux site and learn more about it.


Leave a Reply

Your email address will not be published. Required fields are marked *