foreach

strange json foreach get specified value

风格不统一 提交于 2020-01-07 02:53:09
问题 i have a json code,tried a lot of ways but still can't get the data from the json json: echo $answer->option; // will output {"customer_ans":["qqq","sss"], "show_image":["images/a.png","images/b.png"]}, {"customer_ans":["ooo","ooo","ooo"], "show_image":["images/a.png","images/b.png","images/c.png"]} ...thesame...blablabla when i tried foreach($answer->option as $mydata) { foreach($mydata->customer_ans as $values) { echo $values . "\n"; } } no output and I tried $ansopts = json_decode( $answer

PHP foreach loop show each list item while only showing list name once

一曲冷凌霜 提交于 2020-01-07 02:45:25
问题 Please compare the CURRENT and DESIRED results below to see what I'm trying to do. $arr=array( array('list_name'=>'Food', 'list_item'=>'bread'), array('list_name'=>'Food', 'list_item'=>'meat'), array('list_name'=>'Drinks', 'list_item'=>'water'), array('list_name'=>'Drinks', 'list_item'=>'milk') ); foreach($arr as $row){ echo $row['list_name'].'<br>'; echo $row['list_item'].'<br>'; echo '<br>___<br>'; } CURRENT RESULT Food bread ___ Food meat ___ Drinks water ___ Drinks milk ___ DESIRED RESULT

Comparing JSON after foreach loop

半世苍凉 提交于 2020-01-07 00:06:53
问题 I have a JSON file here. I would like to foreach loop through all of the channels, grab their ID, and then compare it to Members who have channel_id in their array of a given channel but am unsure how to accomplish this properly. The idea is to have a list of users currently in the channels in a <li></li> under neath the channel name. $discord = json_decode(file_get_contents('https://discordapp.com/api/servers/'.$id.'/widget.json')); if ($discord->channels) { usort($discord->channels,

Comparing JSON after foreach loop

孤者浪人 提交于 2020-01-07 00:06:39
问题 I have a JSON file here. I would like to foreach loop through all of the channels, grab their ID, and then compare it to Members who have channel_id in their array of a given channel but am unsure how to accomplish this properly. The idea is to have a list of users currently in the channels in a <li></li> under neath the channel name. $discord = json_decode(file_get_contents('https://discordapp.com/api/servers/'.$id.'/widget.json')); if ($discord->channels) { usort($discord->channels,

Comparing JSON after foreach loop

◇◆丶佛笑我妖孽 提交于 2020-01-07 00:06:19
问题 I have a JSON file here. I would like to foreach loop through all of the channels, grab their ID, and then compare it to Members who have channel_id in their array of a given channel but am unsure how to accomplish this properly. The idea is to have a list of users currently in the channels in a <li></li> under neath the channel name. $discord = json_decode(file_get_contents('https://discordapp.com/api/servers/'.$id.'/widget.json')); if ($discord->channels) { usort($discord->channels,

How to have loop move to the next id available rather than doing the same continuously?

老子叫甜甜 提交于 2020-01-06 20:01:23
问题 Right now when I run this it keeps clicking on the same button every 2 seconds. I'm trying to figure out how I can go on to the next ID rather than it keep doing the first one it finds then breaking. Here is my code: private void button2_Click(object sender, EventArgs e) { timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { HtmlDocument doc = webBrowser1.Document; HtmlElementCollection links = doc.GetElementsByTagName("a"); foreach (HtmlElement link in links) { if (link

Strange variable overwrite in foreach loop

亡梦爱人 提交于 2020-01-06 19:33:43
问题 This must be something ugly obvious, but I'm stucked on this and can't solve it for past two hours. I have this piece of code: foreach($idMap as $menuId=>$pageId) { echo('$this->update("menus_items", SET "link = /content/show?id='.$pageId.'" WHERE id = '.$menuId.');'."\n"); $this->update ( 'menus_items', array('link'=>'/content/show?id='.$pageId), array('id = '.$menuId) ); } echo part works as expected ( $pageId is different for each item, taken from $idMap ), while Yii's CDbCommand::update()

Loop through a list and combine totals where an identifier is the same

耗尽温柔 提交于 2020-01-06 18:31:13
问题 I cuurently have a list of objetcs Cars The variables within are: Make Model Service Cost Lets say I have the list filled up with: Ferrari, F50, 300 Porsche, 911, 700 Toyota, Camary, 300 Porsche, 911, 400 BMW, Z4, 1200 Porsche, 911, 900 Porsche, 356A, 700 As you can see, my list contains three records where the Porsche 911 has service costs. How would I loop through my list, find the duplicate 911's and combine them to form one single record? So that I end up with: Ferrari, F50, 300 Porsche,

How to echo each row from mySQLi query using PHP?

穿精又带淫゛_ 提交于 2020-01-06 15:51:23
问题 The following query returns all rows from the campaign table that have the user_id of 1: SELECT * FROM campaign WHERE user_id=1 In the case of testing this is two results. How would I be able to echo a set column from each of the rows. For example, I want to echo the campaign_name from each of the results. I have tried various methods however, I have had no success. My end goal would be something like this: <?php foreach($queryRow as $row) { ?> <li> <a> <div> <p><?php echo($row['campaign_name

awk/grep replace 2nd match after first match in text file while in foreach loop

Deadly 提交于 2020-01-06 15:21:50
问题 Okay I will try to describe my problem here. I have a file that looks like this: sta WP00 34.07335 -106.91932 1.43 time 10/23/2013 20:10:17 net XO datalogger Passcal_q330_linear 0100000EAA23E50F # 2847 sensor trillium_240_2 0 583 axis Z 0 0 - 1 1 axis N 0 90 - 2 1 axis E 90 90 - 3 1 samplerate 40sps channel Z BHZ 00 channel N BHN 00 channel E BHE 00 samplerate 1sps channel Z LHZ 00 channel N LHN 00 channel E LHE 00 add close sensor trillium_240_2 10/23/2013 20:10:17 sensor trillium_120 0 279