Page 1 of 1

Zeilen in ein 2D-Array verschieben: Kann eine Schleife innerhalb einer Array-Deklaration verwendet werden?

Posted: 23 Jan 2025, 06:21
by Guest
Ich starre seit fast anderthalb Stunden auf diesen Code. Aufgrund meiner Unerfahrenheit habe ich keine Ahnung, wo ich falsch liege.

Code: Select all

$gameInfo = array(
for ($i = 0; $i < 10; $i++) {
$friendsInfo[$i] = $facebook->api('/' . $randomfriends[$i]);
array(
$randomfriends[$i],
$friendsInfo[$i][first_name],
$friendsInfo[$i][last_name],
$friendsInfo[$i][hometown][name],
$friendsInfo[$i][location][name],
$friendsInfo[$i][about]
);
}
);
Das ist mein Versuch. Wie Sie sehen können, werden die Werte von Facebook übernommen. Dies ist nicht das Problem, da jeder Wert angezeigt wird, wenn ich ihn wiederhole. Ich möchte die Werte nehmen und sie in ein mehrdimensionales Array einfügen, das dieser Struktur folgt.

Code: Select all

$gameInfo =  array(
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about')
);