In this code I gave return $array
and I'm using the data inside foreach
, so far so good.
I'd also like to use the $url_controle
variable inside the file that I called the function.
Question: How can I print this variable in the other file? I gave return $url_controle
but it did not seem to work.
function list_all_pages() {
$url_controle = $_SERVER['REQUEST_URI'];
$url_controle = explode('/', $url_controle);
$url_controle = $url_controle[2];
global $pdo;
$sql = "SELECT * FROM tb_paginas WHERE tipo = '$url_controle' ORDER BY ID DESC";
$exc = $pdo->query($sql);
$cnt = $exc->rowCount();
$array = $exc->fetchAll(PDO::FETCH_ASSOC);
return $array;
}
################
EM OUTRO ARQUIVO
################
$pages = list_all_pages();
foreach ($pages as $valores) {
echo $valores['ID'];
echo $valores['titulo'];
}