doyz51819 2015-01-27 20:08
浏览 24

在所有索引上的另一个数组的foreach迭代中迭代数组

PHP. I have two MySQL tables. I want to make fieldsets and checkboxes. I don't know how to use indexes.

buddies, with each a friend_id. assets, with each an asset_id, an asset_name, and a friend_id referring to you know what.

I know how to get through one index. I don't know how to do the rest.

print_r($buddies) echoes:

Array ( [0] => stdClass Object ( [friend_id] => Peter ) [1] => stdClass Object ( [friend_id] => Stephanie ) )

print_r($assets) echoes

Array ( [0] => Array ( [0] => stdClass Object ( [asset_id] => 39 [asset_name] => apple [friend_id] => Peter ) [1] => stdClass Object ( [asset_id] => 50 [asset_name] => pear [friend_id] => Peter ) [2] => stdClass Object ( [asset_id] => 51 [asset_name] => banana [friend_id] => Peter ) ) [1] => Array ( [0] => stdClass Object ( [asset_id] => 44 [asset_name] => apple [friend_id] => Stephanie ) ) )

My PHP code:

<?php 
 foreach ($buddies as $buddy) 
 {
     echo "<fieldset>";
     foreach ($assets as $asset)
     {
         if ($asset[0]->friend_id == $buddy->friend_id)
         {
             echo "<input value=\"".$asset[0]->asset_id."\">". $asset[0]->asset_name . "</input>";
         }
     }
     echo "</fieldset>";
 }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集