I have define the variable $query but it says it's undefined variable

Hi everyone, so today i started writing a page in PHP until i got this error message:
Notice : Undefined variable: query in C:\Users\Ioann\usbwebserver\root\carshop\index.php on line 19
The variable query is defined in functions.php and yet it still thinks it’s undefined

my functions.php

<?php
$host="localhost";
$username="root";
$password="usbw";
$dbname="test";
$pdo= new PDO("mysql:host=$host; dbname=$dbname", $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND =>"SET NAMES utf8"]);
try{
}
catch(PDOException $e){
    echo "error please try again";
}

function appearcars(){
$select = $pdo ->prepare("SELECT * FROM `carshopdatabase` ");
$select ->execute();
$query = $select ->fetch();
}

?>

and my index.php

<?php
require("functions.php");
?>
<html>
<head><title>car shop - educational purposes please don't take anything seriously!!</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="utf-8" http-equiv="encoding">
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
</head>
<body>
<div id="a">Our shop have the best cars around!!!</div>
<div id="lmenu"><ul>
    <li class="top">Home</li>
    <li>Browse cars</li>
    <li>Spare parts</li>
    <li class="bottom">Contuct us</li>
</ul></div>
<div id="carlist"><?php echo $query[1]["cost"]; ?></div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="scripts.js"></script>
</body>

</html>

so, what’s going wrong here?

Ok, i found it!
it couldn’t found it because it was in the function that i wasn’t run it yet!