如何在php中打印多维数组

如何在php中打印多维数组

本文介绍了如何在php中打印多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!我有一个以下格式的数组I have an array in below formatArray ( [0] => Array ( [product_id] => 33 [amount] => 1 ) [1] => Array ( [product_id] => 34 [amount] => 3 ) [2] => Array ( [product_id] => 10 [amount] => 1 ) )我想从该数组获取以下格式的输出I want to get output from that array as below formatProduct ID Amount33 134 310 1任何人都可以在这个问题上帮助我.变量的var_dump是.Can anyone please help me regarding this problem. var_dump of the variable is.array 0 => array 'product_id' => string '33' (length=2) 'amount' => string '1' (length=1) 1 => array 'product_id' => string '34' (length=2) 'amount' => string '3' (length=1) 2 => array 'product_id' => string '10' (length=2) 'amount' => string '1' (length=1)推荐答案我相信这是您的数组$array = Array ( 0 => Array ( "product_id" => 33 , "amount" => 1 ) , 1 => Array ( "product_id" => 34 , "amount" => 3 ) , 2 => Array ( "product_id" => 10 , "amount" => 1 ) );使用foreachecho "<pre>";echo "Product ID\tAmount";foreach ( $array as $var ) { echo "\n", $var['product_id'], "\t\t", $var['amount'];}使用array_mapecho "<pre>" ;echo "Product ID\tAmount";array_map(function ($var) { echo "\n", $var['product_id'], "\t\t", $var['amount'];}, $array);输出Product ID Amount33 134 310 1 这篇关于如何在php中打印多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 05:03