dsqdpn31467 2013-04-25 15:50
浏览 24
已采纳

将多维数组分隔为单独的数组

I am trying to get my head around arrays.

The arrays should look like this:

$questions[$a] => array( [0] => No, comment1
                         [1] => Yes, comment2
                         [2] => No, comment3 )

$answer[$a] => array( [0] => No
                      [1] => Yes
                      [3] => No )

$comment[$a] => array( [0] => comment1
                       [1] => comment2
                       [3] => comment3 )

=========================================================================

SECOND EDIT: Need to execute this in the loop to create a third array -

if($answer[$a] == "Yes") { $display[$a] = "style='display:none'"; 
} else { $display[$a] = "style='display:block'"; }

This is what i have: (28th for minitech)

while ($a > $count)
{
if($count > 11) {
foreach($questions as $q) {
    list($answer, $comments[]) = explode(',', $q);
    if($answer === "Yes") { 
    $display[$a] = "style='display:none'"; 
    } else { 
    $display[$a] = "style='display:block'"; 
    }

$answers[] = $answer;
    }
  }
$a++;
}
  • 写回答

8条回答 默认 最新

  • dongxi2163 2013-04-27 19:56
    关注

    If they are actually strings, explode works:

    $answers = array();
    $comments = array();
    $display = array();
    
    foreach(array_slice($questions, 11) as $question) {
        list($answer, $comments[]) = explode(',', $question);
        $display[] = $answer === 'Yes' ? 'style="display: none"' : 'style="display: block"';
        $answers[] = $answer;
    }
    

    Here’s a demo!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作