回答編集履歴

1 修正

papinianus

papinianus score 12451

2019/03/27 14:39  投稿

```php
var_export($array_sample);
```  
```php  
<?php  
$array = [array(  
 "name" => "name1",  
 "value" => "value1"  
),  
array(  
 "name" => "name2",  
 "value" => "value2"  
),  
array(  
 "name" => "name3",  
 "value" => "value3"  
)];  
echo prettyPrint2DArray($array);  
function prettyPrint2DArray($arr) {  
   $ret = [];  
   foreach($arr as $elm) {  
       $ret[] = prettyPrint1DArray($elm);  
   }  
   return implode(",".PHP_EOL, $ret);  
}  
function prettyPrint1DArray($assoc) {  
   $ret = "array(".PHP_EOL;  
   $vals = [];  
   foreach($assoc as $key => $value) {  
       $vals[] = " \"{$key}\" => {$value}";  
   }  
   $ret .= implode(",".PHP_EOL, $vals).PHP_EOL;  
   $ret .= ")";  
   return $ret;  
}  
```

思考するエンジニアのためのQ&Aサイト「teratail」について詳しく知る