我正在处理数组中的用户数据,我想在不使用 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 Edit
user1 edit
user2 edit
user3 edit
守着星空守着你