PHP在另一个内部循环一个数组

I'm trying to loop one array inside another and then reset the inside array once its reached its end for a Dating site http://www.arab.dating

I have one array that is being filled from a database query. This I'm very familiar with and is like the following:

$sql="SELECT users from users LIMIT 100;";
$pds=$database->pdo->prepare($sql); $pds->execute(array()); $rows=$pds->fetchAll();

I then need to fill another array with data and I've tried 2 ideas being:

1.

$accountArray[] = array('1' => 'data', '2' => 'data', '3' => 'data', '4' => 'data');
$accountArray[] = array('1' => 'data', '2' => 'data', '3' => 'data', '4' => 'data');
$accountArray[] = array('1' => 'data', '2' => 'data', '3' => 'data', '4' => 'data');

2.

$accountArray = array(array(1 => 'data',
                                    2 => 'data',
                                    3 => 'data',
                                    4 => 'data'
                                ),
                            array(1 => 'data',
                                    2 => 'data',
                                    3 => 'data',
                                    4 => 'data'
                                ),
                            array(1 => 'data',
                                    2 => 'data',
                                    3 => 'data',
                                    4 => 'data'
                                )
                        );

Finally I need to loop through the initial array with the second array inside and then reset/restart the second array once it finishes.

    $num = 0;
    foreach($rows as $value) {
        $message = ucfirst($value['users'];
        echo $message;


        echo $accountArray[$num++]['1'];
}

sorry if this is a little ruff.

I trying to get a solution where I can loop through the DB return and then continue to loop through the internal $accountArray[] (which isn't as long as the external $rows Array).

Also would like to know how to best file the $accountArray[] as I think my syntax is a touch off.

thanks you Adam

First of all, the initiation of your $accountArray is good enough. Maybe it could be improved based upon the contents of the array, but with the data you supplied, the initialisation is perfectly fine.

Concerning the looping of the two arrays: the easiest thing is to work with modulo (if you divide the two sides of the operation, the result of the modulo is the remainder) on this one. Since the keys of the query-result-array are sequential, we can use the following approach:

<?php

$sql = "SELECT users from users LIMIT 100;";
$pds = $database->pdo->prepare($sql);
$pds->execute(array());
$rows = $pds->fetchAll();

$accountArray = array(
    array(
        '1' => '0',
        '2' => 'data', 
        '3' => 'data', 
        '4' => 'data',
    ),
    array(
        '1' => '1',
        '2' => 'data', 
        '3' => 'data', 
        '4' => 'data',
    ),
    array(
        '1' => '2',
        '2' => 'data', 
        '3' => 'data', 
        '4' => 'data',
    ),
);

$accountCount = count($accountArray);  // do this outside of the loop for performance
foreach($rows as $key => $row) {
    $marker = $key % $accountCount;    // the actual magic for selecting the correct array-index

    $message = ucfirst($row['users']);
    echo $message;
    echo $accountArray[$marker]['1'];  // do what you want with the result
}