2016-06-06 8 views
0

My db-Tabelle ist:php, wie Werte in Array zu duplizieren (mehrdimensionale)

author    book     repeat 
------    ----     ------ 
Paulo Coelho   the alchemist   2 
Adam Smith   The Wealth of Nations 1 

Ich hole Daten von db mit dem folgenden PHP-Code:

... 
$books_array[]= array(
     'author'=> $row['author'], 
     'book'=> $row['book'], 
); 

Aber ich weiß nicht, wie um die Werte gemäß meinem Wiederholungswert zu wiederholen. Wie kann ich das folgende Array erhalten?

array 
    [0] => Array 
     (
      [author] => Coelho 
      [book] => The Alchemist 
     ) 

    [1] => Array 
     (
      [author] => Coelho 
      [book] => The Alchemist 
     ) 

    [2] => Array 
     (
      [author] => Smith 
      [book] => The Wealth of Nations 
     ) 

Vielen Dank!

Antwort

0

Oups! Nur darüber nachgedacht! Das war einfach!

abgegeben Just

for($i= 0 ; $i <= $row['repeat'] ; $i++){ 
    $books_array[]= array(
    'author'=> $row['author'], 
    'book'=> $row['book'], 
    ); 
}; 

Hope this jemand anderem hilfreich sein wird :) !!!!