php 数组问题

php中文网
发布: 2016-06-23 14:04:35
原创
1074人浏览过

我dump了一个数组,显示如下:

array(9) {  [0] => array(6) {    ["que_content"] => string(11) "11111111111"    ["que_id"] => string(1) "1"    ["ops_qid"] => string(1) "1"    ["ops_contentoid"] => string(1) "A"    ["ops_content"] => string(14) "aaaaaaa1111111"    ["ops_count"] => string(1) "3"  }  [1] => array(6) {    ["que_content"] => string(11) "11111111111"    ["que_id"] => string(1) "1"    ["ops_qid"] => string(1) "1"    ["ops_contentoid"] => string(1) "B"    ["ops_content"] => string(10) "bbbbbbbbbb"    ["ops_count"] => string(1) "1"  }  [2] => array(6) {    ["que_content"] => string(11) "11111111111"    ["que_id"] => string(1) "1"    ["ops_qid"] => string(1) "1"    ["ops_contentoid"] => string(1) "C"    ["ops_content"] => string(8) "cccccccc"    ["ops_count"] => string(1) "1"  }  [3] => array(6) {    ["que_content"] => string(9) "222222222"    ["que_id"] => string(1) "2"    ["ops_qid"] => string(1) "2"    ["ops_contentoid"] => string(1) "D"    ["ops_content"] => string(9) "ddddddddd"    ["ops_count"] => string(1) "3"  }  [4] => array(6) {    ["que_content"] => string(9) "222222222"    ["que_id"] => string(1) "2"    ["ops_qid"] => string(1) "2"    ["ops_contentoid"] => string(2) "EF"    ["ops_content"] => string(12) "efe2efef2fef"    ["ops_count"] => string(1) "1"  }  [5] => array(6) {    ["que_content"] => string(9) "222222222"    ["que_id"] => string(1) "2"    ["ops_qid"] => string(1) "2"    ["ops_contentoid"] => string(1) "F"    ["ops_content"] => string(14) "fff32fffffffff"    ["ops_count"] => string(1) "1"  }  [6] => array(6) {    ["que_content"] => string(9) "333333333"    ["que_id"] => string(1) "3"    ["ops_qid"] => string(1) "3"    ["ops_contentoid"] => string(2) "GG"    ["ops_content"] => string(13) "ggg323ggggggg"    ["ops_count"] => string(1) "1"  }  [7] => array(6) {    ["que_content"] => string(9) "333333333"    ["que_id"] => string(1) "3"    ["ops_qid"] => string(1) "3"    ["ops_contentoid"] => string(1) "H"    ["ops_content"] => string(10) "hhh5h5h5h5"    ["ops_count"] => string(1) "2"  }  [8] => array(6) {    ["que_content"] => string(9) "333333333"    ["que_id"] => string(1) "3"    ["ops_qid"] => string(1) "3"    ["ops_contentoid"] => string(1) "J"    ["ops_content"] => string(8) "j8j8j8j8"    ["ops_count"] => string(1) "2"  }}
登录后复制


我想输出的时候这样子输出,应该要怎样做?
问题:11111111111选项:A    内容:aaaaaaa1111111选项:B    内容:bbbbbbbbbb选项:C    内容:cccccccc问题:222222222选项:D    内容:ddddddddd选项:EF    内容:efe2efef2fef选项:F    内容:fff32fffffffff问题:333333333选项:GG    内容:ggg323ggggggg选项:H    内容:hhh5h5h5h5选项:J    内容:j8j8j8j8
登录后复制

AI建筑知识问答
AI建筑知识问答

用人工智能ChatGPT帮你解答所有建筑问题

AI建筑知识问答 22
查看详情 AI建筑知识问答

回复讨论(解决方案)

刚刚弄出来你看看:

foreach($a as $v){  if($qid!=$v['ops_qid']){	echo '问题:'.$v['que_content']."<br>";	$qid=$v['ops_qid'];  }else{    echo '选项:'.$v['ops_contentoid'].'     内容'.$v['ops_content']."<br>";  }}
登录后复制

貌似要稍加改动:
代码如下:

foreach($a as $v){  if($qid!=$v['ops_qid']){    echo '问题:'.$v['que_content']."<br>";    echo '选项:'.$v['ops_contentoid'].'     内容'.$v['ops_content']."<br>";    $qid=$v['ops_qid'];  }else{    echo '选项:'.$v['ops_contentoid'].'     内容'.$v['ops_content']."<br>";  }}
登录后复制

if($qid!=$v['ops_qid'])


$qid是指什么啊?

$qid 是一个临时变量,用于存放上一轮的 ops_qid。这样就可以检查到是否是新问题了

to nowphp
为什么要改成 #2 的样子,将 #1 的 else 删掉不就可以了吗?

$qid 是一个临时变量,用于存放上一轮的 ops_qid。这样就可以检查到是否是新问题了

to nowphp
为什么要改成 #2 的样子,将 #1 的 else 删掉不就可以了吗? 是的,是的,版主仔细,我粗心了。

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号