I have this code:
$pages = $conn->prepare('SELECT * FROM pages WHERE slug = startpage');
$pages->execute();
$resultarray = array();
while($row = $pages->fetch(PDO::FETCH_ASSOC)){
$resultarray[] = $row;
}
I’m trying to do this because I want to use the array in the whole document, not just inside the while. See below example:
//Somewhere outside of the while loop
<h1><?php echo $resultarray['header']?></h1>
What is the most efficient way to do this?
1 Answer