在生成数组的PHP for循环中即时插入添加的逻辑

Situation: I have a front-page slider where users can select from a menu of options which pages they want to include in a front-page slider. The options are stored in a static array and only print the selections of the user up to whatever limit I determine, please see code below.

<?
        // Counts the Number of Boxes available for the front page slider
        $numberOfBoxes = 6; 

        $group = array (); // Create an empty array to store all of your final data


        //Counts all the checkboxes and their corresponding sliderboxes
        for ( $a = 1; $a <= $numberOfBoxes; $a++ )
        {
            if (${'checkBox_'.$a} == TRUE){

            $tempDefaultArray = ${'sliderBox_'.$a};
            array_push($group , $tempDefaultArray); // Push the data to the $group array
            }
        }

        $arraySize = sizeof($group); // Find the size of the final array

        // Take the outcome from the above calculations and create slider
        for ( $i = 0; $i <= ($arraySize - 1); $i++ )
        {
            $image = $group[$i]['image'];
            $title = $group[$i]['title'];
            $tagline = $group[$i]['tagline'];
            $url = $group[$i]['url'];
            $vanityUrl = $group[$i]['vanityUrl'];

            print'
            <li '.$sliderDivider.'>
            <img src="'.$image.'" border="0"/>
            <h1>'.$title.'</h1>
            <p>'.$tagline.'</p>
            <a href="'.$url.'" '.$sliderLink.'/>'.$vanityUrl.'</a>
            ';}?>

Problem: This works perfectly, but I want to state that if a particular external variable isset and/or true that the third box in my slider will populate data from a specific object in my array. I would like to maintain the functionality of this existing logic, and just incorporate some extra to override the third box if that variable is set.

Example: I choose for my slider options to be: Article 1, Article 2, Blog 1, Image 1, and then in a separate area of the customization the user selects YouTube videos. By default when that variable isset, lets call it $youTube then the third selection (in this ex Blog 1) would default to the YouTube. Additional note, this default box lives in the same array as the static options.

This is kind of a tricky thing to explain, and if their are any ninja PHPrs out there that could recommend an efficient way to handle this I would appreciate it.

Hmm, if I understand your question right, you want to have an override within your loop if a certain condition is set outside the array variables?

You can put an if statement in your loop checking the external variable:

if($external_var=="something") {
    $image = $static_array['image'];
    $title = $static_array['title'];
    $tagline = $static_array['tagline'];
    $url = $static_array['url'];
    $vanityUrl = $static_array['vanityUrl'];
} else {
    $image = $group[$i]['image'];
    $title = $group[$i]['title'];
    $tagline = $group[$i]['tagline'];
    $url = $group[$i]['url'];
    $vanityUrl = $group[$i]['vanityUrl'];
}