0

hi all,
I cannot understand for what reason and how is used call_user_func_array
Can anyone explain me in a very simple manner what is call_user_func_array? and with examples if possible
Thanks in advance

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Kraai
0

thank you very much. but what advantages does this function have? if possible can you explain it in this example
and for what reason here used & operator

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

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

?

<?php

function read()
{
   $parameters = array();
   $results = array();

   $mysql = new mysqli('localhost', 'root', 'root', 'db') or die('There was a problem connecting to the database');
   $stmt = $mysql->prepare('SELECT body FROM posts') or die('Problem preparing query');
   $stmt->execute();

   $meta = $stmt->result_metadata();

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

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

   call_user_func_array(array($stmt, 'bind_result'), $parameters);

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

   return $results;

}

$results = read();
?>
<!DOCTYPE html>

<html lang="en">
<head>
   <meta charset="utf-8">
   <title>untitled</title>
</head>
<body>
<?php foreach ($results as $row) : ?>

   <p> <?php echo $row['body']; ?> </p>
<?php endforeach; ?>
</body>
</html>

thanks for attention

Edited by azegurb: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.