PHP arrays a foreach loop

$cars =[
  ["Volvo",22,18],
  ["BMW",15,13],
];

Ako prejsť foreach loopom 2 polia naraz? (musia byť rovnako veľké polia )

$images = ['1.jpg', '2.jpg']
$pages = ['stranka1', 'stranka2']

foreach( $images as $index => $image ) {
    echo $pages[$index] . ' ' . $image . '<br>';
 }

foreach (array_combine($images, $pages) as $image => $page) {
     echo '<br>' .$image . ' > ' . $page  ;
 }

Ako vytvoriť pole zo všetkých súborov v priečinku ?

$pages = glob("*.php");
$images = glob("/nazov priecinka/*.jpeg");

Multi asociativne pole

$stranky = [
    ['url' => 'stranka1',   'class' => 'energy'],
    ['url' => 'stranka2',     'class' => 'energy'],
    ['url' => 'stranka3',     'class' => 'energy'],
    ['url' => 'stranka4',     'class' => 'energy'],
    ['url' => 'stranka5',  'class' => 'ga'],
    ['url' => 'stranka6',   'class' => 'ga'],
    ['url' => 'stranka7',     'class' => 'lano'],
    ['url' => 'stranka8',    'class' => 'lano'],
];

echo $stranky[0]['ural];

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená.