-1

我想如何遍历这个数组以在 html 列表中打印类似的内容(一个 foreach 或任何其他循环应该可以完成工作......)。我完全卡住了..!

Caballos  Soledad'
    'Paseo a caballo' 
...........
...........
...........
Rancho Valle
     'Camping'
    'Paseo a caballo' 

array (size=10)
  40 => 
    array (size=2)
      'proveedor' => string 'Caballos Soledad' (length=26)
      'servicio' => 
        array (size=1)
          0 => string 'Paseo a caballo' (length=15)
  41 => 
    array (size=2)
      'proveedor' => string 'Caballos Segundo' (length=25)
      'servicio' => 
        array (size=1)
          0 => string 'Paseo a caballo' (length=15)
  64 => 
    array (size=2)
      'proveedor' => string 'Cerro' (length=10)
      'servicio' => 
        array (size=1)
          0 => string 'Camping' (length=7)
  39 => 
    array (size=2)
      'proveedor' => string 'Caballos Nieto' (length=19)
      'servicio' => 
        array (size=1)
          0 => string 'Paseo a caballo' (length=15)
  174 => 
    array (size=2)
      'proveedor' => string 'Hacienda' (length=21)
      'servicio' => 
        array (size=2)
          0 => string 'Paseo a caballo' (length=15)
          1 => string 'Camping' (length=7)
  49 => 
    array (size=2)
      'proveedor' => string 'Campo ' (length=10)
      'servicio' => 
        array (size=1)
          0 => string 'Camping' (length=7)
  241 => 
    array (size=2)
      'proveedor' => string 'Lodge' (length=12)
      'servicio' => 
        array (size=1)
          0 => string 'Paseo a caballo' (length=15)
  258 => 
    array (size=2)
      'proveedor' => string 'Modesto' (length=14)
      'servicio' => 
        array (size=1)
          0 => string 'Paseo a caballo' (length=15)
  294 => 
    array (size=2)
      'proveedor' => string 'Rancho Valle ' (length=18)
      'servicio' => 
        array (size=2)
          0 => string 'Camping' (length=7)
          1 => string 'Paseo a caballo' (length=15)
  38 => 
    array (size=2)
      'proveedor' => string 'Caballos Jose ' (length=22)
      'servicio' => 
        array (size=1)
          0 => string 'Paseo a caballo' (length=15)

我一直在寻找太久......但没有找到合适的方法来做到这一点。提前谢谢了

4

2 回答 2

0

所以,我改变了我喜欢的格式

function my_print_r($array){

    foreach ($array as $key => $value){

        if (is_array($value)){
            echo '<ul>';
            my_print_r($value);
            echo '</ul>';
        }
        else echo '<li> ' . $value;

    }
      echo '</li>';
   // echo '</ul>';
}
于 2013-01-26T20:00:34.503 回答
0
function my_print_r($array){
    echo '<ul>';
    foreach ($array as $key => $value){
        echo '<li>' . $key;
        if (is_array($value)){
            my_print_r($value);
        }
        else echo ' : ' . $value;
        echo '</li>';
    }
    echo '</ul>';
}

希望这会奏效,只需根据需要更改格式:)

于 2013-01-25T01:14:17.270 回答