I am confused about &reference operator. here i dont understand
the call_user_array_func() and
referense operator why used here?
but can you explain it on my code
original source is
http://net.tutsplus.com/tutorials/ph...ed-statements/
i tested it. i want to know what happens there
i know this & reference operator but for what reason this is used i cannot understand. this section

while ( $field = $meta->fetch_field() ) {

     $parameters[] = &$row[$field->name];
   }

and from where $row variable has come?

while ( $stmt->fetch() ) {
      $x = array();
      foreach( $row as $key => $val ) {
         $x[$key] = $val;
      }
      $results[] = $x;
   }

Thanks again for attention

$meta = $stmt->result_metadata();

while ( $field = $meta->fetch_field() ) {  
  
     $parameters[] = &$row[$field->name];  
   }  
  
   call_user_func_array(array($stmt, 'bind_result'), $parameters);

First, it gets the metadata of your query. Then, it gets all field names, and adds a reference to the value in the array $row with the key $field->name to $parameters.
Normally, if you would have for example SELECT id, title, body FROM posts , you would have to call $stmt->bind_result($row['id'], $row['title'], $row['body']) . But as you have those references in an array, you have to call call_user_array_func() .
Its first parameter array($stmt, 'bind_result') stands for $stmt->bind_result, and that function is than called with the parameters in $parameters , the second parameter :)

Hope that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.