7.2.2、二维数组中包含自定义键数组的打印

 
 PHP Code By tony
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

    $products = array(
                
array('产品名'=>'苹果','数量'=>6,'价格'=>28.2),
                
array('产品名'=>'猪肉','数量'=>3,'价格'=>36.3),
                
array('产品名'=>'饼干','数量'=>3,'价格'=>28.3)
            );
    
    
//  print_r($products);
    
    
//  echo $products[0]['价格'].'<br>';
    //  echo $products[1]['价格'].'<br>';
    
    
//  echo 'foreach<br>';
        
    
//  // foreach 
    //  for ($i=0;$i<count($products);$i++){
    //      foreach ($products[$i] as $key=>$value){
    //          echo $key.'|'.$value.'|';
    //      }
    //      echo '<br>';
    //  }
    
    
echo 'each<br>';
    print_r($products);
    
    
// each
    for ($j=0;$j<count($products);$j++){
        
while (!!list($key,$value) = each($products[$j])){
            
echo 'print';
            
echo $key.'|'.$value.'|';
        }
        
echo '<br>';
    }
    
?>




原文地址:https://www.cnblogs.com/tonycody/p/2795373.html