按顺序输出数组

时间:2017-05-26 15:50:06

标签: php

我有一些代码,我们的开发人员不再在这里为我们写信。它是装甲的规格。阵列按其必须始终显示的顺序列出。但是它没有以此顺序出现在前端。有人可以告诉我代码的错误并指出我正确的方向

$explode_armoring_level = explode(',',$nij);

        # list all armoring levels  
        $armoring_level_array = array('ii','iiia','iii','iv');

        # remove any empty values and reset array to parse
        $remove_empty_array = array_filter($explode_armoring_level);

        # count array so we do not show active class when array empty
        $armoring_level_count = count($remove_empty_array);

        # loop through all selected levels for posted ID/vehicle id
        foreach($remove_empty_array as $key => $eal)
        {
            # find last value in array and set class
            if ($eal == end($explode_armoring_level) && $armoring_level_count > 0)
            {
                # returns active armoring level list
                $vehicle_data .= '<li class="active">'.ucwords($eal).'</li>' . "\r\n";
            }
            else
            {
                # returns active armoring level list
                $vehicle_data .= '<li>'.ucwords($eal).'</li>' . "\r\n";
            }
        }


        # run loop to find remaining armoring levels that were not selected
        foreach($explode_armoring_level as $ala)
        {
            if (in_array($ala, $armoring_level_array)) 
            {
                unset($armoring_level_array[array_search($ala,$armoring_level_array)]);
            }           
        }

        $count = 1;

        # output remaining armoring levels
        foreach($armoring_level_array as $key => $alag)
        {
            if($count == 1 && $armoring_level_count == 0)
            {
                # returns active armoring level list
                $vehicle_data .= '<li class="active non-active">'.ucwords($alag).'</li>' . "\r\n";
            }
            else
            {
                # returns active armoring level list
                $vehicle_data .= '<li class="active">'.ucwords($alag).'</li>' . "\r\n"; 
            }

            $count++;
        }

根据发布ID

选择车辆
    $get_vehicle_details = "SELECT post_id,meta_key,meta_value FROM wp_postmeta WHERE post_id = '".$post->ID."'";
    $get_vehicle_details_result = $link->query($get_vehicle_details);

    # error array
    $err = array();

    # loop through results
    while($row = $get_vehicle_details_result->fetch_assoc())
    {
        # identify meta_key you want and assign value
        if($row['meta_key'] == 'euro-norm')     {$euro_norm      = $row['meta_value'];}
        if($row['meta_key'] == 'nsa')           {$nsa            = $row['meta_value'];}
        if($row['meta_key'] == 'nij')           {$nij            = $row['meta_value'];}
        if($row['meta_key'] == 'ul-armor-level'){$ul_armor_level = $row['meta_value'];}
        if($row['meta_key'] == 'vpam')          {$vpam           = $row['meta_value'];}
    }

    # if values are Empty/FALSE then push into error array
    if($euro_norm == '')     {array_push($err, 'euro_norm');}
    if($nsa == '')           {array_push($err, 'nsa');}
    if($nij == '')           {array_push($err, 'nij');}
    if($ul_armor_level == ''){array_push($err, 'ul_armor_level');}
    if($vpam == '')          {array_push($err, 'vpam');}        

    # count total errors
    $row_error = count($err);

    # if error count is less than 5 or not 5 / show vechile data
    if($row_error < 5 or $row_error != 5)
    {

0 个答案:

没有答案