如何匹配foreach循环内的多个数组?

m'y question is: How to match multiple arrays (two, or even more) inside a foreach loop (or while)

here is m'y <code>Var_dump</code>

$cat = $bdd->query('SELECT cat_name FROM categories');
$categories_list = $cat->fetchAll(PDO::FETCH_COLUMN);


$cat_id = $bdd->query('SELECT cat_id FROM categories');
$categories_id = $cat_id->fetchAll(PDO::FETCH_COLUMN);


$arrcatid = array($categories_list,$categories_id);

echo '<form method="post" action="accès/create_topic_post.php" autocomplete="off">';
echo '<label for="sujet">Sujet :';
echo '<input type="text" name="sujet" id="sujet" required autofocus>';
echo '</label>';
echo '<label for="cat">Catégories :';
echo '<select name="topic_name">';



foreach ($categories_list as $cat_name){
echo "<option value=\"$cat_name\">$catname</option>";
}
$cat_id->closeCursor();
$cat->closeCursor();


echo '</select>';
echo '</label>';
echo '<input type="submit" value="Envoyer">';
echo '</form>';
var_dump($arrcatid);

So, the goal is to match array 0 with array 1 cat_name && cat_id

Thanks a lot :D

I used :

$cat = $bdd->query('SELECT cat_name,cat_id FROM categories');
$categories_list = $cat->fetchAll(PDO::FETCH_KEY_PAIR);

and for the foreach :

foreach ($categories_list as $cat_id => $cat_name){
echo "<option value=\"$cat_name\">$cat_id</option>";

How about getting both the name and the id in the sql query?

$cat = $bdd->query('SELECT cat_name, cat_id FROM categories');

 

</div>