What to do and do in php

I have this code

$myNewClass->cars =& Orders_Car::GetRecords($myNewClass->searchString);
                   ^

what is doing there &. thank

+3
source share
4 answers

Read Do Not Use PHP Links by PHP Expert Johannes Schluter

PHP links are a respite from PHP 4, where objects were passed by value, not by reference, unless you specifically made them by reference. This is not necessary when using PHP 5, because all objects are passed by reference to PHP 5 all the time.

Scalars and arrays are passed by default to PHP 5 by default. If you need to pass them by reference, you just need to use the object.

+4
source

, . .

. .

- foreach.

, foreach .

$salad=array(1,2,3);
foreach ($salad as $leaf){
  $leaf+=1;
  }
echo $salad[0];// output: 1   

foreach ($salad as &$leaf){
  $leaf+=1;
  }
echo $salad[0];// output: 2 because & made the assignment affect the original array
+6

He creates a link. If you do not know what a link is, read the following: http://www.php.net/manual/en/language.references.php

+6
source

Source: https://habr.com/ru/post/1748554/


All Articles