<?php $arr = ["Entrada" => 4, "Prato principal" => 1]; $res = array_reduce(array_keys($arr), function($novoArr, $chave) use ($arr){ $novoArr[] = Array($chave, $arr[$chave]); return $novoArr;}); var_dump($res);
Standard input is empty
array(2) { [0]=> array(2) { [0]=> string(7) "Entrada" [1]=> int(4) } [1]=> array(2) { [0]=> string(15) "Prato principal" [1]=> int(1) } }
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!