PHP Issue with sorting events and arrays, also combining booleans
<p>I believe this code that is used to sort events as folows is giving me an issue. The errors it is triggering is :</p>

<pre><code>Notice: Undefined variable: combined in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 941

Notice: Undefined offset: 3 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 893

Notice: Undefined offset: 3 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 895

Notice: Undefined variable: combined in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 941

Notice: Undefined offset: 4 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 893

Notice: Undefined offset: 4 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 895

Notice: Undefined variable: combined in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 941

Notice: Undefined offset: 5 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 893

Notice: Undefined offset: 5 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 895

Notice: Undefined variable: combined in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 941

Notice: Undefined offset: 6 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 893

Notice: Undefined offset: 6 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 895

Notice: Undefined variable: combined in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 941

Notice: Undefined offset: 7 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 893

Notice: Undefined offset: 7 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 895

Notice: Undefined variable: combined in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 941

Notice: Undefined offset: 8 in /services10/webpages/c/m/cms.norlink.ca/public/admin/new_events.php on line 893
</code></pre>

<p>The code is the following:        </p>

<pre><code>  function sortevents($days_events)
        {
    if (!is_array($days_events))
    {
        return array();
    }
    if (0 === ($ec=count($days_events)))
    {
        return array(); 
    }
    $neworder = array();
    $oldorder_used = array();
    $allordered = false;
    for ($i = 0; $i &lt;= $ec; $i++)
    { 
        $oldorder_used[$i] = false; 
    }
    $i = 0;
    $sd = null;
    $si = -1;
    $ei = 0;
    while (!$allordered)
    {
        if ((null == $sd || $sd &gt; $days_events[$i]['startint']) &amp;&amp; !$oldorder_used[$i])
        {
            $sd = $days_events[$i]['startint'];
            $si = $i;
        }
        else
        {
            $i++;
            continue;
        }

        if ($i === ($ec-1))
        {
            $oldorder_used[$si] = true;
            $neworder[$ei] = $days_events[$si];
            $ei++;
            $i = 0;
        }
        $i++;
        $allordered = combinebooleans($oldorder_used);
    }
}

//takes an array of booleans and combines them
function combinebooleans($arr_bools)
{
    //if not an array of booleans
    if (!is_array($arr_bools))
    {
        //if not a boolean
        if (!is_bool($arr_bools)) 
        { 
            return false; 
        }
        //if it is a boolean then lets return it
        else 
        { 
            return $arr_bools; 
        }
    }
    else
    {
        //variable to hold combined booleans
        $combined;

        //cycle through the array of booleans and 
        foreach ($arr_bools as $curb) 
        { 
            $combined = $combined | $curb; 
        }
        return $combined;
    }
}
</code></pre>
