dongshi3361 2012-10-23 03:36
浏览 11
已采纳

将数组和子数组包装在无序列表中

I am using an API call that returns an array. It's an array not a sting. I want to wrap the array in an unordered list. I need two separate lists.

1) I want to wrap everything (including sub arrays) in an unordered list.

<ul>
  <li>[name]</li>
  <li>[name]</li>
  <li>[name]</li>
</ul>

2) I just want to wrap [name] in an unordered list.

<ul>
  <li>[1347037874]</li>
    <ul>
      <li>[level_id]</li>
      <li>[name]</li>
      <li>[canceled]</li>
      <li>[cancelDate]</li>
      <li>and all the rest</li>
    </ul>
  <li>[1347037874]</li>
    <ul>
      <li>[level_id]</li>
      <li>[name]</li>
      <li>[canceled]</li>
      <li>[cancelDate]</li>
      <li>and all the rest</li>
    </ul>
</ul>

I assign the API call like this:

$member_id = $logged_in_WP_user_id;
$member_levels = member_levels($member_id);

For explanation only (this line is not in my function...when I output $member_levels like this: htmlspecialchars(print_r(get_member($member_id),true)) I get the following:

Array
( 
    [1347037874] => stdClass Object
        (
            [Level_ID] => 1347037874
            [Name] => HFM-Cardiac Resistance Training Program
            [Cancelled] => 
            [CancelDate] => 
            [Pending] => 
            [UnConfirmed] => 
            [Expired] => 
            [ExpiryDate] => 
            [Active] => 1
            [Status] => Array
                (
                    [0] => Active
                )

            [Timestamp] => 1349804951
            [TxnID] => WL-2-1347037874
        )

    [1347037875] => stdClass Object
        (
            [Level_ID] => 1347037875
            [Name] => HFM-Official Heart Health Guide
            [Cancelled] => 
            [CancelDate] => 
            [Pending] => 
            [UnConfirmed] => 
            [Expired] => 
            [ExpiryDate] => 
            [Active] => 1
            [Status] => Array
                (
                    [0] => Active
                )

            [Timestamp] => 1349804951
            [TxnID] => WL-2-1347037875
        )
)

I have tried several ways to wrap the array in an array, it get close but still can make it work right.

Tks!

p.s. here is what I am now using to make the first list but how do I get the other key values to display as in unordered list under the key value =>Name.

$member_levels = ember_levels($member_id);

  $output  = '';    
  $output .= '<ul>';                            
  foreach($member_levels as $level) {
    $output .= '<li>' . $level_array[]=$level->Name . '</li>';
  }
  $output .= '</ul>';

  print_r($output);
  • 写回答

2条回答 默认 最新

  • douduoting8408 2012-10-23 04:09
    关注
    foreach($member_levels as $level)
    {
    
      $level_array[]=$level->Level_ID;
      $name_array[]=$level->Name;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答