Welcome Guest, Not a member yet? Register   Sign In
Attempting to modify the result_array. Help!
#7

[eluser]jedd[/eluser]
Veering off ever so slightly to one side -- I've never done the &$var thing in order to insert data into an extant array like this - instead I've simply generated a new array, often bringing one of the values from the array (say the id field from the table) into play as the key for a new dimension. Err, you know what I mean.

Anyhoo, out of curiosity I had a quick play with the reference approach, as described on that PHP.net page I cited earlier, and I'm seeing an odd appearance of an ampersand in my output.

Here's my code:
Code:
<?php
    $foo = array();
    $foo[] = array ("a"=>"alpha", 'b'=>"bravo", 'c'=>"charlie");
    $foo[] = array ("a"=>"alpha", 'b'=>"bravo", 'c'=>"charlie");

    var_dump ($foo);

    echo " --- ";

    foreach ($foo as &$bar)
        $bar['d'] = 'delta';

    var_dump ($foo);

This is the unadulterated output that's generated - specifically note the 1 = & bit in the second section.
Code:
array
  0 =>
    array
      'a' => string 'alpha' (length=5)
      'b' => string 'bravo' (length=5)
      'c' => string 'charlie' (length=7)
  1 =>
    array
      'a' => string 'alpha' (length=5)
      'b' => string 'bravo' (length=5)
      'c' => string 'charlie' (length=7)

---
array
  0 =>
    array
      'a' => string 'alpha' (length=5)
      'b' => string 'bravo' (length=5)
      'c' => string 'charlie' (length=7)
      'd' => string 'delta' (length=5)
  1 => &
    array
      'a' => string 'alpha' (length=5)
      'b' => string 'bravo' (length=5)
      'c' => string 'charlie' (length=7)
      'd' => string 'delta' (length=5)

If I add in an extra array in the setup - the & appears on 2 => &, but not on 1 - ie, it follows the last array's index.

Any ideas?


Messages In This Thread
Attempting to modify the result_array. Help! - by El Forum - 10-09-2009, 06:21 PM
Attempting to modify the result_array. Help! - by El Forum - 10-09-2009, 06:31 PM
Attempting to modify the result_array. Help! - by El Forum - 10-09-2009, 06:35 PM
Attempting to modify the result_array. Help! - by El Forum - 10-09-2009, 06:37 PM
Attempting to modify the result_array. Help! - by El Forum - 10-09-2009, 06:37 PM
Attempting to modify the result_array. Help! - by El Forum - 10-09-2009, 06:42 PM
Attempting to modify the result_array. Help! - by El Forum - 10-10-2009, 08:50 AM
Attempting to modify the result_array. Help! - by El Forum - 10-10-2009, 10:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB