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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘