Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ref of an array in PHP 5?

Tags:

php

reference

In php 5, all variable and objects are passed by reference, but i can't get my codes work

My codes is:

$arrayA = array();

$array = $arrayA;
...
if(!in_array(thedata, $array)
    $array[] = thedata;
var_dump($arrayA);

The result is empty, am i missing something simple?

like image 467
Edward Avatar asked Dec 09 '22 16:12

Edward


1 Answers

<?php
    $arrayA = array();
    $arrayB =& $arrayA;
    $arrayB = array(1,2,3);
    var_dump($arrayA);

Read more here:

http://php.net/manual/en/language.types.array.php (Search for Reference)

http://www.php.net/manual/en/language.references.php

like image 97
Ivo Sabev Avatar answered Dec 24 '22 06:12

Ivo Sabev