foreach

How to display JSON data readable way for users in laravel?

折月煮酒 提交于 2020-01-04 05:17:13
问题 In my controller i have like this public function show(Document $document){ $doc = DB::table('adjustments')->where('document_id', $document->id)->get(); return view('documents.show',compact('document','doc')); } In my view i have like this @foreach($doc as $user) <pre>{{ $user->before}}</pre> <pre>{{ $user->after}}</pre> @endforeach Im getting output like this {"title":"Nam beatae tempora nulla magnam accusantium neque eligendi magni.","body":"Unde doloremque omnis aspernatur atque illo

Allowed memory size exhausted in PHP for loop

我只是一个虾纸丫 提交于 2020-01-04 03:12:50
问题 I'm facing a fatal error while I'm trying to manipulate a huge array of arrays in PHP and return the result as a response of an HTTP POST request : Allowed memory size of 536870912 bytes exhausted I have already tried to set ini_set('memory_limit', '-1'); in order to see if I get the result, but I didn't get any type of response. Postman crashed all the times that I tried to make the POST request. The starting structure of the array is this one. The body size is around 25mb. The main array

PHP: Will using array_splice on an array that's the subject of a foreach() cause problems?

被刻印的时光 ゝ 提交于 2020-01-04 02:20:08
问题 I am writing some PHP code that's kind of like this: foreach($filter[1] as $reject){ $reject_processed = preg_replace('~\s~','',strtolower($filter[1][$reject])); if(array_key_exists($reject_processed,$list_of_common_replacements)){ $filter[0][] = $list_of_common_replacements[$reject_processed]; $filter[1] = array_splice($filter[1],$reject,1) } } It's supposed to search through a list of rejected values (filter[1]), find if a replacement exists, then (if so) add the replacement to the list of

Why foreach works while removing items from ListView and doesn't work from ListBox?

▼魔方 西西 提交于 2020-01-03 19:37:16
问题 I've started learning C# and I'm a bit confused about the behavior that I discovered. I try to figure out, why in one case the code is working and in another not: foreach (ListViewItem l in listView1.SelectedItems) l.Remove(); foreach (object l in listBox1.SelectedItems) listBox1.Items.Remove(l); First one works fine and there is no error, but the second one throws exception with information that the collection was changed. Could anyone explain it to me? PS. In case of ListView I was

Unable to filter collection of objects to select only those with latest date

邮差的信 提交于 2020-01-03 18:38:59
问题 I have a collection of objects named $items : I want to filter $items down to not contain duplicates according to the FullName property but have the unique object be the one with the latest date. Since I couldn't figure out how to do that my solution approach was to first create a new object that only contains the duplicates in the form of the FullName property named $duplicateItems : $arrDuplicates = @{} $duplicateItems = foreach ($row in $restoreItems.FullName) { if ($arrDuplicates

What is “:” doing in this beginners java example program using generics?

好久不见. 提交于 2020-01-03 18:37:59
问题 Okay so I need help understanding something. I understand how "? :" are used together but reading over some beginning Java stuff I see this situation popping up in a few places. Most recently is this... public static <U> void fillBoxes(U u, List<Box<U>> boxes) { for (Box<U> box : boxes) { box.add(u); } } What I am confused about is what exactly ":" is doing. Any help would be appreciated. I am looking at this example on a page at Oracle's website, located here: http://download.oracle.com

What is “:” doing in this beginners java example program using generics?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 18:36:13
问题 Okay so I need help understanding something. I understand how "? :" are used together but reading over some beginning Java stuff I see this situation popping up in a few places. Most recently is this... public static <U> void fillBoxes(U u, List<Box<U>> boxes) { for (Box<U> box : boxes) { box.add(u); } } What I am confused about is what exactly ":" is doing. Any help would be appreciated. I am looking at this example on a page at Oracle's website, located here: http://download.oracle.com

Problem with anonymouse delegate within foreach

夙愿已清 提交于 2020-01-03 17:52:55
问题 public Form1() { InitializeComponent(); Collection<Test> tests = new Collection<Test>(); tests.Add(new Test("test1")); tests.Add(new Test("test2")); foreach (Test test in tests) { Button button = new Button(); button.Text = test.name; button.Click+=new EventHandler((object obj, EventArgs arg)=>{ this.CreateTest(test); }); this.flowLayoutPanel1.Controls.Add(button); } } public void CreateTest(Test test) { MessageBox.Show(test.name); } } when i click the button witch text is 'test1', the

Codeigniter using foreach in view

萝らか妹 提交于 2020-01-03 17:01:09
问题 I'm using Codeigniter on an Apache xampp set up and attempting to use foreach in a view for the first time and I just can't get it to work. My Controller code: class Test extends CI_Controller { public function index($page = 'testv') { if ( ! file_exists(APPPATH.'/views/'.$page.'.php')) { show_404(); } $this->load->model('testm'); $data['news'] = $this->testm->get_news(); $this->load->view('headder'); $this->load->view($page, $data); $this->load->view('footer'); } } My Model: class Testm

Nested foreach in PHP produces different results than I expect

混江龙づ霸主 提交于 2020-01-03 12:24:03
问题 I'm having problems to iterate twice on the same array: <? $indice=0 ?> <?php foreach ($comisiones as $comision1):?> <tr> <td><?php echo ++$indice ?></td> <td><?php echo tag('select',array('name'=>'comision_'.$indice),true)?> <?php foreach ($comisiones as $comision2):?> <option value="<?php echo $comision2->getId()?>"> <?php echo $comision2->getNombre()." - ".$comision2->getDescripcion()?> </option> <?php endforeach?> </select> </td> </tr> <?php endforeach?> The above code prints: And I'm