Most voted "foreach" questions
Provides an easy way to iterate over vectors and matrices.
Learn more…324 questions
Sort by count of
- 
		1 votes1 answer55 viewsReceive array valuesHow I receive the values of this checkbox? <input type="checkbox" name="Item[<?php echo $IDCatalogo; ?>][<?php echo $IDItem; ?>]"> foreach( $_POST['Item'] as $key => $n ) {… 
- 
		1 votes0 answers108 viewsProblems generating JSON with JAVAI’m having trouble generating this json { "receita": [{ "specialtys": [{ "date": "27/01/2016 00:00:00", "itemSpecialtys": [{ "specialtyId": 1, "specialtyName": "Tabelionato de Notas", "receitas": [{… 
- 
		1 votes2 answers860 viewsArray of unique values with foreachI got the following foreach to pick up the id of the devices that were used in each sector: @foreach($relatorio->Empresa->SetorEmpresa as $setor) {{ $collection[] =… 
- 
		1 votes1 answer529 viewsInvalid argument supplied for foreach() Using JSONI’m trying to traverse the foreach with a populated JSON array. To make it easier I’m testing via $_GET (but I’ve tried it with an array populated by php but it didn’t work). The $_GET is like this:… 
- 
		1 votes1 answer573 viewsSubcategory listing according to selected categoryI have the following code snippet: <?php foreach($categorias as $cat){ $id_cat = $cat['id']; $subcategorias = array(); $sqlsub = Comando::Executar("SELECT * FROM subcategoria WHERE cat_pai =… 
- 
		1 votes1 answer360 viewsYou can use a foreach of a query within a functionI have a query simple: $Consulta = $pdo->query(" SELECT * FROM dados ")->fetchAll(); foreach ($Consulta as $key) { echo $key["InfoDado"]; } If you execute the foreach of it out of a function!… 
- 
		1 votes0 answers232 viewsReceive all data from a table with only one queryI am trying to create a system that uses Lastfm images. But I want to show only the images of the artists registered in the database. I did so: I made a bank query on condition that banda_id was not… 
- 
		1 votes3 answers12476 views
- 
		1 votes1 answer8366 views
- 
		1 votes1 answer959 views
- 
		1 votes0 answers67 viewsForeach inside if CakephpI have an A table that stores an item, and in this table, I have a related B that may have several items aggregated to an item in table A. Follow the if code: if… 
- 
		1 votes2 answers1361 viewsDisplay only one record with foreachI need help to display only one database record, follow code: <?php $posts = DBRead( 'posts', "WHERE categoria = 3 AND status = 1 ORDER BY data_numero ASC" ); if( !$posts ) echo… 
- 
		1 votes2 answers865 viewsHow to use data from an Array without foreachI have a function in my Model: public function get_learning_category_list() { $categorias = $this->db->select('t1.id, t1.title, t1.metadata, t1.meta_title, t1.description, t1.meta_description,… 
- 
		1 votes1 answer200 viewsforeach shows 1 wait file then clears and shows another phpI have a foreach in PHP and it shows various data of a XML, but in this XML has 5 photos and I would like the loop to show the first photo, wait about 10 seconds and then show the second photo so… 
- 
		1 votes1 answer318 viewsUsing Else inside the foreachGuys I have the following code: <?php $string = $_POST['search']; foreach($results['results']['collection1'] as $collection) { if(stristr($collection['prod']['text'],$string) !== false) { echo… 
- 
		1 votes0 answers97 viewsPHP/Bootstrap - Replay up to X and then up to Y then includes new DIV and continues replayI’m breaking my head in this repetition, as this is my first question, sorry for the mistakes. :) Currently I have this block of codes inside the container: <?php echo '<div class="row">';… 
- 
		1 votes1 answer76 viewsError using Sqlcommand and foreachI’m trying to go through a list of objects and persist your data in Sqlserver: foreach (var item in pedidos) { cmd.CommandText = "INSERT INTO MinhaTabela (Coluna_A, Coluna_B, Coluna_C) " + "VALUES… 
- 
		1 votes1 answer194 viewsInterim records in foreachI’m making a list of records and I’m having the following difficulty: In my system I have two tables and I need to list their records interchangeably. The location of the listing is the same. Only I… 
- 
		1 votes2 answers512 viewsHow to get the values of an array from a keyI need to get the values ( $src ), inside this foreach, of each key separately in this array: <?php foreach( get_post_gallery( $post->id, false ) as $key => $src ) { echo $key; //resultado:… 
- 
		1 votes2 answers332 viewsRead string json in phpI need to read the file below: string '{"object":"list","hasMore":true,"limit":10,"offset":0,"data":[{"city":{"object":"city","id":15873,"ibgeCode":"3550308","name":"São… 
- 
		1 votes1 answer799 viewsRead data in an SQL with columns of equal names in different tablesI need to recover data from 2 tables. My SQL presented below works perfectly. The problem is that I made a foreach to recover data from the second table by field ID that is conflicting with the… 
- 
		1 votes1 answer63 viewsI cannot print an array with foreachI cannot print my array when I put a different key, it gives the error Warning: Invalid argument supplied for foreach(), how to proceed? for ($i=0; $i < 2; $i++) { $use[$i]['outrachave'] = 'some… 
- 
		1 votes1 answer180 viewsHow to complement these queries to get the buyer’s data in the bank?I made these queries below to get the data from the buyer’s database and the products he bought. With the first query, I got the ID and with these IDS I made a new foreach that took the products… 
- 
		1 votes1 answer48 viewsCreate columns with knockoutJS foreachGood afternoon, I wanted to 'break' a list of items in 3 columns of 4 items in a knockoutJS foreach. That is, at this point the list is filled down and I would like it to be started via jQuery or… 
- 
		1 votes1 answer40 viewsforeach with errorSomeone can give me a hand here, I made this train to take the weekdays, until all right, plus the foreach($periodo as $item) don’t list the last day, someone can tell me what I’m doing wrong! $ini… 
- 
		1 votes2 answers1094 viewsTypeerror: Cannot read Property 'Concat' of Undefined - Typescript?if (dataFindCategories && dataFindCategories.length !== 0) { let dataFindProducts: Product[]; dataFindCategories.forEach((category) => {… 
- 
		1 votes0 answers25 viewsStop PHP foreach loop after startHow to interrupt a foreach PHP based on a condition coming from the database after starting the loop? $smtm = Connect::getInstance()->query("SELECT * FROM table WHERE num IS NULL"); foreach… 
- 
		1 votes3 answers140 viewsHow do I place a conditional within a . foreach() in Javascript?I’m making a Scrapping on a website that organizes items with a tag <a>, however I am getting several values with null. How can I place a parole to avoid these values null on the return? const… 
- 
		1 votes1 answer2049 viewsForeach in Select and ListI recently discovered that there’s a big difference between doing some operations, like Select and Where, in Queryable and listed objects such as Enumerable and List. In this and in this question.… 
- 
		1 votes1 answer106 viewsLaravel - Doubt about @foreach?I have the following code: @foreach($listaProdutos as $key => $listaProduto) @if(...) ... @endif @endforeach Is there any command or way to jump to the next record of $listaProduto if the… 
- 
		1 votes1 answer177 viewsforeach with multiple variablesI’m trying a foreach with several variables like? $record = array(); foreach($resultCustomers as $group) { $record[$group['CODIGO_CLIENTE'].$group['RAZAOSOCIAL']][] = $group['NOME']; } $output =… 
- 
		1 votes1 answer569 viewsInsert array foreacham tend a problem when entering data in the database with php , I have a form with several checkbox , then I want to select more than 1 checkbox and insert in the database , I did so form <input… 
- 
		1 votes1 answer535 viewsCapture results using HtmlagilitypackI’m using this code to get results using the Html Agility Pack. This is how it is: WebRequest request = WebRequest.Create(texto); WebResponse response = request.GetResponse(); StreamReader reader =… 
- 
		1 votes1 answer336 viewsHow to encode json with multiple objects in PHPI need the following result: { "sala": [{ "horario": "18:30", "data": "Seg e Terça" }, { "horario": "10:30", "data": "Quarta Terça" }] } UPDATE I’m doing it like this in PHP: /*criando objeto… 
- 
		1 votes1 answer244 viewsForeach without repeating the nameI have a Foreach in View, and it contains Description, Qtd and dta,how do I make a foreach without repeating the description? Ex: I have a product X whose were removed 10 units day 01/10/2016, 3… 
- 
		1 votes0 answers93 viewsHow to add a comma to each loop string by omitting only the last string?I have a loop that is generating several names, but need the result of this loop is merged into only one string and names are separated by commas, but omitting the comma in the last name. Expected… 
- 
		1 votes1 answer147 viewsError foreach codeigniterI’m in the following problem, I make one select in the database and display the images on the page, is a classified portal where the person makes an ad and can upload up to 10 images. So far so… 
- 
		1 votes1 answer183 viewsTwo php foreachs - Duplicate dataI have two selects that return me two arrays and I need to go through them, in the same table, but the records are being duplicated. How can I best resolve this issue ? Follow the example: <?php… 
- 
		1 votes1 answer324 viewsDuplicate items in ForeachI have two Inputs (curso[] and formacao[]) html and when loop with the foreach and starts to duplicate the items that are within the second foreach This is my class class Pessoa { private $Formacao;… 
- 
		1 votes1 answer149 viewsPHP for each with an if ruleI have a table that brings paid and unpaid commission results. I want him to bring only the pay, I mean, if number_format($row->amount_paid,2) = 0 not bring that line. <?php $i=-1;… 
- 
		1 votes1 answer50 viewsForearch loop how to use with controlerI’m 6 PictureEdit in a PanelControl, and I need to make a run at all the PictureEdit then I made the following code: foreach (PictureEdit Pic in panel1.Controls) { //habilita o meno de zoom… 
- 
		1 votes1 answer548 viewsForeach with this type of JSON (PHP)I am trying to display the values of a JSON with PHP more unsuccessfully. Code Used: JSON: { "event_name": "offline_message", "widget_id": "sEcXk3TXEw", "visitor": { "name": "ARTULITO BARBOSA DE… 
- 
		1 votes1 answer161 views
- 
		1 votes0 answers76 viewssimplexml_load_file does not return any recordI have the following routine for reading XML file: $arquivo_geral = "xml_categ_1.xml"; if (file_exists($arquivo_geral)) { $xml = simplexml_load_file($arquivo_geral); foreach($xml->categoria as… 
- 
		1 votes1 answer85 viewsHow to return array indices in methodWell I couldn’t find a better title for my case, I have the following function: public function select_tokens() { $sql = "SELECT * FROM `users`"; $select_tokens = Database::DB()->prepare($sql);… 
- 
		1 votes0 answers203 viewsGet JSP foreach value in Jquery to display in labelI would like help to catch a figure that is set within a forEach in my JSP, play for Jquery and it display in a label on the same page. That one forEach retrieves a direct list from the database. I… 
- 
		1 votes1 answer162 viewsAccessing Rasor variables inside a foreachI am trying to list the contents of a table, showing in each item the items of another table that maintains a relationship with the first (1:N). For this I need 2 select, being the 2nd select based… 
- 
		1 votes2 answers771 viewsSort foreach in phpI made a page that shows the hash in several hash_algos in order to study their differences, but I would like to sort by the hash size and not by the hash_algos name, the code is this, <?php… 
- 
		1 votes1 answer3068 viewsError: Invalid argument supplied for foreach()I’m having a problem displaying my mailing list, is giving this error: Warning: Invalid argument supplied for foreach() in /###/###/###/view/list.php on line 11 In the file it’s like this: <div… 
- 
		1 votes1 answer587 viewsInsert JSON file into database via PHPI have a JSON file that I need to do the Insert of the information contained in it in the database. JSON file:…