Dear documentation team,

I have tried several times to submit a note to the documentation of the php manual. This, however, has been impossible.  Here is my note:

+--- NOTE BEGINS HERE --------------------------------------

Sergio Santana: [EMAIL PROTECTED]

Sometimes we need functions for building or modifying arrays whose elements are to be references to other variables (arrays or objects for instance). In this example, I wrote two functions 'tst' and 'tst1' that perform this task. Note how the functions are written, and how they are used.

<?
function tst(&$arr, $r) {
  // The argument '$arr' is declared to be passed by reference,
  // but '$r' is not;
  // however, in the function's body, we use a reference to
  // the '$r' argument
 
  array_push($arr, &$r);
  // Alternatively, this also could be $arr[] = &$r (in this case)
}
 
$arr0 = array();          // an empty array
$arr1 = array(1,2,3);   // the array to be referenced in $arr0

// Note how we call the function:
tst($arr0, &$arr1); // We are passing a reference to '$arr1' in the call !

print_r($arr0); // Contains just the reference to $arr1

array_push($arr0, 5); // we add another element to $arr0
array_push($arr1, 18); // we add another element to $arr1 as well

print_r($arr1); 
print_r($arr0); // Changes in $arr1 are reflected in $arr0

// -----------------------------------------
// A simpler way to do this:

function tst1(&$arr, &$r) {
  // Both arguments '$arr' and '$r" are declared to be passed by
  // reference,
  // again, in the function's body, we use a reference to
  // the '$r' argument
 
  array_push($arr, &$r);
  // Alternatively, this also could be $arr[] = &$r (in this case)
}

 
$arr0 = array();          // an empty array
$arr1 = array(1,2,3);   // the array to be referenced in $arr0

// Note how we call the function:
tst1($arr0, $arr1); // 'tst1' understands '$r' is a reference to '$arr1'

echo "-------- 2nd. alternative ------------ <br>\n";

print_r($arr0); // Contains just the reference to $arr1

array_push($arr0, 5); // we add another element to $arr0
array_push($arr1, 18);

print_r($arr1); 
print_r($arr0); // Changes in $arr1 are reflected in $arr0


?>

// This outputs:
// X-Powered-By: PHP/4.1.2
// Content-type: text/html
//
// Array
// (
//     [0] => Array
//         (
//             [0] => 1
//             [1] => 2
//             [2] => 3
//         )
//
// )
// Array
// (
//     [0] => 1
//     [1] => 2
//     [2] => 3
//     [3] => 18
// )
// Array
// (
//     [0] => Array
//         (
//             [0] => 1
//             [1] => 2
//             [2] => 3
//             [3] => 18
//         )
//
//     [1] => 5
// )
// -------- 2nd. alternative ------------
// Array
// (
//     [0] => Array
//         (
//             [0] => 1
//             [1] => 2
//             [2] => 3
//         )
//
// )
// Array
// (
//     [0] => 1
//     [1] => 2
//     [2] => 3
//     [3] => 18
// )
// Array
// (
//     [0] => Array
//         (
//             [0] => 1
//             [1] => 2
//             [2] => 3
//             [3] => 18
//         )
//
//     [1] => 5
// )

In both cases we get the same result.

I hope this is somehow useful


Sergio.
+--- NOTE ENDS HERE --------------------------------------

And, here is the notification I receive each time:

"There was an internal error processing your submission. Please try to submit again later."


This has happened for several days. Is there a problem with my submission or with your server?


Thank you very much for your attention,


Sergio.
INSTITUTO MEXICANO DE TECNOLOGIA DEL AGUA
(Mexican Institute for Water Technology)




-- 
---------------------------------------------------------------------------------
Julio Sergio Santana          [EMAIL PROTECTED]
                              [EMAIL PROTECTED]
Tel. +52 777 3293600 ext 867, Tel/Fax +52 777 3293679
http://jssantana.tripod.com/Formal/

"Que el Dios de paz, que resucitó de los muertos a nuestro Señor
Jesucristo, el gran pastor de las ovejas, por la sangre del pacto eterno,
los capacite en todo lo bueno para hacer su voluntad ..." (Heb. 13:20,21)
---------------------------------------------------------------------------------

Reply via email to