doucandiao9180 2015-09-14 07:38 采纳率: 100%
浏览 254
已采纳

使用PHP在数值数组中打印关联数组

I have a numerical array for which each row is an associative array. A var_dump on this array is like :

array (size=4)
  0 => 
array (size=1)
  'brand' => string 'Daewoo' (length=6)
  1 => 
array (size=1)
  'brand' => string 'Honda' (length=5)
  2 => 
array (size=1)
  'brand' => string 'Mazda' (length=5)

How can I loop through this multi-dimensional array to show in a select/option the value of the key "brand" ?

I tried something like a for loop with a foreach loop inside but my associative array has no name, it's not declared as a variable.

Any idea ?

  • 写回答

1条回答 默认 最新

  • duancaishi1897 2015-09-14 07:43
    关注

    How about this:

    foreach ($numerical_array AS $row) {
      print ("<option>" . $row['brand'] . "</option>");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?