我正在處理數組中的用戶數據,我想在不使用 foreach 循環的情況下在 html 表中打印用戶數據,而是使用 array_walk()<?php $users=$this->db->get('user')->result(); echo '<table><tr><th>Name</th><th>Edit</th></tr><tbody>'; function myfunction($value,$key){ echo '<tr><td>'.$value.'</td><td>Edit</td></tr>';}echo '</tbody></table>';$a=array("a"=>"user1","b"=>"user2","c"=>"user3");array_walk($a,"myfunction");?>預期輸出:Name Edituser1 edituser2 edituser3 edit
使用 array_walk 或 array_map 在 html 表中顯示數組結果
慕的地8271018
2021-11-19 16:15:25