如何在循环中回显特定数组的slug

时间:2017-07-03 19:21:37

标签: php arrays wordpress

我这里有一个数组但是我想要回显数组中第8个键的single_name,我只是想知道我该怎么做呢?

      $stm_listings_update_options = array ( 
     1 => array ( 'single_name' => 'Condition', 'plural_name' => 'Conditions', 'slug' => 'condition', 'font' => '', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => false, 'use_on_car_filter' => true, 'use_on_car_modern_filter' => true, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => true, ), 
     2 => array ( 'single_name' => 'Body', 'plural_name' => 'Bodies', 'slug' => 'body', 'font' => 'stm-service-icon-body_type', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => true, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => true, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'listing_rows_numbers' => 'two_cols', 'enable_checkbox_button' => false, ), 
     3 => array ( 'single_name' => 'Make', 'plural_name' => 'Makes', 'slug' => 'make', 'font' => '', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => false, 'use_on_car_filter' => true, 'use_on_car_modern_filter' => true, 'use_on_car_modern_filter_view_images' => true, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => true, 'enable_checkbox_button' => false, 'use_in_footer_search' => true, ), 
     5 => array ( 'single_name' => 'Model', 'plural_name' => 'Models', 'slug' => 'serie', 'font' => '', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => false, 'use_on_car_filter' => true, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => true, 'listing_taxonomy_parent' => 'make', 'enable_checkbox_button' => false, 'use_in_footer_search' => true, ),
     6 => array ( 'single_name' => 'Mileage', 'plural_name' => 'Mileages', 'slug' => 'mileage', 'font' => 'stm-icon-road', 'numeric' => true, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => true, 'use_on_car_archive_listing_page' => true, 'use_on_single_car_page' => true, 'use_on_car_filter' => true, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'number_field_affix' => 'mi', 'enable_checkbox_button' => false, ), 
     7 => array ( 'single_name' => 'Fuel type', 'plural_name' => 'Fuel types', 'slug' => 'fuel', 'font' => 'stm-icon-fuel', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => true, 'use_on_single_car_page' => true, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, ), 
     8 => array ( 'single_name' => 'Engine', 'plural_name' => 'Engines', 'slug' => 'engine', 'font' => 'stm-icon-engine_fill', 'numeric' => true, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => true, 'use_on_single_car_page' => true, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'enable_checkbox_button' => false, 'use_in_footer_search' => false, ), 
     9 => array ( 'single_name' => 'Year', 'plural_name' => 'Years', 'slug' => 'ca-year', 'font' => 'stm-icon-road', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => false, 'use_on_car_filter' => true, 'use_on_car_modern_filter' => true, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'enable_checkbox_button' => false, ), 
     10 => array ( 'single_name' => 'Price', 'plural_name' => 'Prices', 'slug' => 'price', 'font' => 'stm-icon-road', 'numeric' => true, 'use_on_single_listing_page' => true, 'use_on_car_listing_page' => true, 'use_on_car_archive_listing_page' => true, 'use_on_single_car_page' => false, 'use_on_car_filter' => true, 'use_on_car_modern_filter' => true, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'enable_checkbox_button' => false, ), 
     11 => array ( 'single_name' => 'Fuel consumption', 'plural_name' => 'Fuel consumptions', 'slug' => 'fuel-consumption', 'font' => 'stm-icon-fuel', 'numeric' => true, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => true, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => false, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, ), 
     12 => array ( 'single_name' => 'Transmission', 'plural_name' => 'Transmission', 'slug' => 'transmission', 'font' => 'stm-icon-transmission_fill', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => true, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => true, 'use_on_car_filter' => true, 'use_on_car_modern_filter' => true, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, ), 
     13 => array ( 'single_name' => 'Drive', 'plural_name' => 'Drives', 'slug' => 'drive', 'font' => 'stm-icon-drive_2', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => true, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => true, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, ), 
     14 => array ( 'single_name' => 'Fuel economy', 'plural_name' => 'Fuel economy', 'slug' => 'fuel-economy', 'font' => '', 'numeric' => true, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => false, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'enable_checkbox_button' => false, ), 
     15 => array ( 'single_name' => 'Exterior Color', 'plural_name' => 'Exterior Colors', 'slug' => 'exterior-color', 'font' => 'stm-service-icon-color_type', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => true, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'enable_checkbox_button' => false, ), 
     16 => array ( 'single_name' => 'Interior Color', 'plural_name' => 'Interior Colors', 'slug' => 'interior-color', 'font' => 'stm-service-icon-color_type', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => true, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => false, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'enable_checkbox_button' => false, ), 
     17 => array ( 'single_name' => 'Features', 'plural_name' => 'Features', 'slug' => 'features', 'font' => '', 'numeric' => false, 'use_on_single_listing_page' => false, 'use_on_car_listing_page' => false, 'use_on_car_archive_listing_page' => false, 'use_on_single_car_page' => false, 'use_on_car_filter' => false, 'use_on_car_modern_filter' => false, 'use_on_car_modern_filter_view_images' => true, 'use_on_car_filter_links' => false, 'use_on_directory_filter_title' => false, 'listing_rows_numbers' => 'one_col', 'enable_checkbox_button' => true, ), );

3 个答案:

答案 0 :(得分:1)

直接回显数组值

echo $stm_listings_update_options[8]['single_name'];

或循环获取第8个元素

foreach(  $stm_listings_update_options as $key =$value){

  if ($key = 8  ){
      echo $value['single_name'];
  }

}

答案 1 :(得分:0)

快速基本方法: echo $stm_listings_update_options[7]['single_name'];

更好:

$i = 7; // Using a variable
$k = 'single_name';
echo $stm_listings_update_options[$i][$k];

我意识到OP可能没有零作为第一个索引。如果数组以'1'作为第一个索引,那么$ i应为8。

答案 2 :(得分:0)

$i = 7; // The array to pick data from
foreach(  $stm_listings_update_options as $data){
//if array number is same as $i then echo Slug
if ($data = $i ) {
echo $data["slug"];
}
}