Count an array of a function?

Asked

Viewed 61 times

0

How do I do echo of counting the result of the following function?

public function get_Myinteresses() 
{
    global $db;
    $myInteresses = array();
    $get_interids = $db->query(sprintf("SELECT * FROM inter_user_conn WHERE iduser = %s", secure($this->_data['user_id'], 'int'))) or _error(SQL_ERROR_THROWEN);      
    if($get_interids->num_rows > 0) 
    {
        while($interids = $get_interids->fetch_assoc()) 
        {
          $nterid = $interids['idinter'];
          $get_Myinteresses = $db->query(sprintf("SELECT * FROM inter_list WHERE idinter = %s", secure($nterid, 'int') )) or _error(SQL_ERROR_THROWEN);
          if($get_Myinteresses->num_rows > 0) 
          {
              while($minteresse = $get_Myinteresses->fetch_assoc()) 
              {
                  $myInteresses[] = $minteresse;
              }
          }
        }
    }
    return $myInteresses;
}
  • Tries echo count(get_Myinteresses());

  • No! Something like that? public Function countMyint(){ $countMyinter = Count(get_Myinteresses(); Return $countMyinter; }

1 answer

0

If I understood correctly, you should just print $get_Myinteresses->num_rows, which would return the amount. You could change the output to return the quantity and the array so you don’t have to calculate.

However, since the function return is an array, you can only use the Count() function in the function return.

$myInteresses =  get_Myinteresses();

$qdt = count($myInteresses);

echo $qdt;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.