Return data from a function?

0

How do I get data from a function, in case I want to make a foreach of an sql query that is in a function:

index.php

<?php
    require_once "funcs/functions.php";
    $userdata = get_user_data();
    foreach ($userdata as $d) {
    $name = $d["nome"];
    $id = $d["id"];
    $matricula = $d["matricula"];

    echo $name."<br>".$id."<br>".$matricula;
    }

functions.php

function get_user_data(){
  $user = $_SESSION["Login"];
  $pass = $_SESSION["Password"];
  $pdo = cnx();
  $select = $pdo->query("select * from matricula where username = '$user'");
  $select->execute();
  $rowCount = $select->rowCount();
  if ($rowCount == 0):
      header("Location:index.php?no=1");
  else:
      foreach ($select as $a):
          $password = $a["password"];
      endforeach;
      if($pass == $password){
        return $select;
      } else {
          header("Location:index.php?no=1");
      }
  endif;
}
    
asked by anonymous 27.08.2017 / 01:45

0 answers