循环确实采取案例函数并返回空结果

时间:2018-05-20 13:50:21

标签: php

我会尝试插入内部下拉信息,但它始终为空。 就像你可以看到代码一样,案例没有注入$ lc_text

for($ col = 0,$ n = count($ column_list); $ col< $ n; $ col ++){

              var_dump($column_list);
              var_dump($column_list[$col]);


              switch ($column_list[$col]) {
                case 'MODULE_PRODUCTS_SEARCH_LIST_DATE_ADDED':
                  $lc_text = OSCOM::getDef('table_heading_date');
                break;
                case 'MODULE_PRODUCTS_SEARCH_LIST_PRICE':
                  $lc_text = OSCOM::getDef('table_heading_price');
                break;
                case 'MODULE_PRODUCTS_SEARCH_LIST_MODEL':
                  $lc_text = OSCOM::getDef('table_heading_model');
                break;
                case 'MODULE_PRODUCTS_SEARCH_LIST_NAME':
                  $lc_text = OSCOM::getDef('table_heading_products');
                break;
                case 'MODULE_PRODUCTS_SEARCH_LIST_MANUFACTURER':
                  $lc_text = OSCOM::getDef('table_heading_manufacturer');
                break;
                case 'MODULE_PRODUCTS_SEARCH_LIST_QUANTITY':
                  $lc_text = OSCOM::getDef('table_heading_quantity');
                break;
                case 'MODULE_PRODUCTS_SEARCH_LIST_WEIGHT':
                  $lc_text = OSCOM::getDef('table_heading_weight');
                break;
              }




var_dump($lc_text);
              $new_lc_text = $OSCOM_ProductsCommon->createSortHeading($_GET['sort'], $col+1, $lc_text);

的var_dump($ new_lc_text);

              $new_prods_content .= '<button class="dropdown-item" type="button">' . $new_lc_text . '</button>';

        }

不同元素的结果:

var_dump($column_list);
array (size=7)
  'MODULE_PRODUCTS_SEARCH_LIST_NAME' => string 'module_products_search_list_name' (length=32)
  'MODULE_PRODUCTS_SEARCH_LIST_MODEL' => string 'module_products_search_list_model' (length=33)
  'MODULE_PRODUCTS_SEARCH_LIST_MANUFACTURER' => string 'module_products_search_list_manufacturer' (length=40)
  'MODULE_PRODUCTS_SEARCH_LIST_PRICE' => string 'module_products_search_list_price' (length=33)
  'MODULE_PRODUCTS_SEARCH_LIST_QUANTITY' => string 'module_products_search_list_quantity' (length=36)
  'MODULE_PRODUCTS_SEARCH_LIST_WEIGHT' => string 'module_products_search_list_weight' (length=34)
  'MODULE_PRODUCTS_SEARCH_LIST_DATE_ADDED' => string 'module_products_search_list_date_added' (length=38)


var_dump($column_list[$col]);
 '<a href="http://localhost/test/boutique/index.php/Search/Q/keywords,t/page,1/sort,1a" title="Sort productsascendinglyby" class="productListing-heading"></a>' (length=169)


var_dump($lc_text);
/home/www/test/boutique/sources/template/Default/modules/modules_products_search/pse_products_search.php:94:null


'var_dump($new_lc_text);
<a href="http://localhost/test/boutique/index.php/Search/Q/keywords,t/page,1/sort,1a" title="Sort productsascendinglyby" class="productListing-heading"></a>'

1 个答案:

答案 0 :(得分:1)

您需要检查数组的,而不是它的值:

foreach ($column_list as $k => $v) {

  switch ($k) {
    case 'MODULE_PRODUCTS_SEARCH_LIST_DATE_ADDED':
      $lc_text = OSCOM::getDef('table_heading_date');
    break;
    case 'MODULE_PRODUCTS_SEARCH_LIST_PRICE':
      $lc_text = OSCOM::getDef('table_heading_price');
    break;
    case 'MODULE_PRODUCTS_SEARCH_LIST_MODEL':
      $lc_text = OSCOM::getDef('table_heading_model');
    break;
    case 'MODULE_PRODUCTS_SEARCH_LIST_NAME':
      $lc_text = OSCOM::getDef('table_heading_products');
    break;
    case 'MODULE_PRODUCTS_SEARCH_LIST_MANUFACTURER':
      $lc_text = OSCOM::getDef('table_heading_manufacturer');
    break;
    case 'MODULE_PRODUCTS_SEARCH_LIST_QUANTITY':
      $lc_text = OSCOM::getDef('table_heading_quantity');
    break;
    case 'MODULE_PRODUCTS_SEARCH_LIST_WEIGHT':
      $lc_text = OSCOM::getDef('table_heading_weight');
    break;
  }

  var_dump($lc_text);
  // I don't know what `$col+1` means, but I suppose it 
  // should be rewritten too, as `$col` is NOT used now
  $new_lc_text = $OSCOM_ProductsCommon->createSortHeading($_GET['sort'], $col+1, $lc_text);

  var_dump($new_lc_text);
  $new_prods_content .= '<button class="dropdown-item" type="button">' . $new_lc_text . '</button>';
}