Search code examples
phparraysloopsfor-loopstylesheet

Getting only the values in Array not keys


What I'm trying to accomplish is using an array to link to CSS stylesheets.

First I create the function to be executed which is styles() The styles() function looks like this..

//CSS Stylesheets Includes
function styles()
{
    $linkStyles = array(
    0 => 'main',
    1 => 'topBar',
    2 => 'globals',
    3 => 'search',
    4 => 'menu',
    5 => 'footer',
    6 => 'banner',
    7 => 'slideshow',
    8 => 'graphs',
    9 => 'contact',
    10 => 'news',
    11 => 'products',
    12 => 'support'
    );

    for($i = 0; $i <= count($linkStyles); $i++)
    {
        ?><link rel="stylesheet" charset="text/css" href="css/style_<?php array($linkStyles[$i]); ?>.css" /><?php
    }
}

Now what I'm having trouble with is working with the Array within the for() loop. I'm not understanding how to acquire just the value within the key of the array.

For example, If I look up the $linkStyles array under key 0 I want it to return just 'main' without the quotations of course. The final output would be something like,

<link rel="stylesheet" charset="text/css" href="css/style_main.css" />

of course since there's a loop, it would have 12 of the links to stylesheets, not just 1.


Solution

  • foreach ($linkStyles as $v)
    {
        echo '<link rel="stylesheet" charset="text/css" href="css/style_' . $v . '.css" />';
    }