Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can take advantage of the fact that PHP will dereference the results of a function call.</p> <p>Here's some example code I whipped up:</p> <pre><code>$x = 'x'; $y = 'y'; $arr = array(&amp;$x,&amp;$y); print_r($arr); echo "&lt;br/&gt;"; $arr2 = $arr; $arr2[0] = 'zzz'; print_r($arr); print_r($arr2); echo "&lt;br/&gt;"; $arr2 = array_flip(array_flip($arr)); $arr2[0] = '123'; print_r($arr); print_r($arr2); </code></pre> <p>The results look like this:</p> <pre> Array ( [0] => x [1] => y ) Array ( [0] => zzz [1] => y ) Array ( [0] => zzz [1] => y ) Array ( [0] => zzz [1] => y ) Array ( [0] => 123 [1] => y ) </pre> <p>You can see that the results of using <code>array_flip()</code> during the assigment of <code>$arr</code> to <code>$arr2</code> results in differences in the subsequent changes to <code>$arr2</code>, as the <code>array_flip()</code> calls forces a dereference.</p> <p>It doesn't seem terribly efficient, but it might work for you if <code>$this-&gt;x-&gt;getResults()</code> is returning an array:</p> <pre><code>$data['x'] = array_flip(array_flip($this-&gt;x-&gt;getResults())); $data['y'] = $data['x']; </code></pre> <p>See <a href="https://stackoverflow.com/questions/894814/deep-copy-of-php-array-of-references">this (unanswered) thread</a> for another example.</p> <p>If everything in your returned array is an object however, then the only way to copy an object is to use <code>clone()</code>, and you would have to iterate through <code>$data['x']</code> and clone each element into <code>$data['y']</code>.</p> <p>Example:</p> <pre><code>$data['x'] = $this-&gt;x-&gt;getResults(); $data['y'] = array(); foreach($data['x'] as $key =&gt; $obj) { $data['y'][$key] = clone $obj; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload