Most voted "foreach" questions
Provides an easy way to iterate over vectors and matrices.
Learn more…324 questions
Sort by count of
-
3
votes1
answer26
views.each() ends when the div is closed
I have the following problem, I have Divs that have a dynamic amount of Divs inside. <div class="grid-f"> <div class="col-4"></div> <div class="col-4"></div> <div…
-
3
votes1
answer122
viewsC# How to change value within Parallel.Foreach
I am performing a processing inside an array of strings (lines of a file . txt). For performance reasons, I’m using the Parallel.ForEach, but there was a need to change the values of some lines that…
-
3
votes2
answers91
viewsForeach preg_match_all
I need to mount an array with all the data coming from another array using preg_match_all,I’m using the following code. $results = array(…
-
3
votes3
answers14457
viewsTraversing Object array and accessing a value
Good afternoon guys, I’m having a difficulty, where I need to access an element of an array of OBJECTS, I’m not being able to access with foreach, or for. I need your help! The array of objects:…
-
3
votes1
answer89
viewsHow to encrypt multiple variables within a php file?
I’m using php to read a file to a $string, he owns some words variables that I need to find and replace with others, that is, I need to get these variables, encrypt them with AES and write again…
-
3
votes1
answer347
viewsForeach in XML with ids and store in a variable to insert data in a given table
Good afternoon, Next, I have a system that already have the registered ids in a table, ( of cars , are opicional of cars) and in the other table where it is registered the cars is called these IDS…
-
3
votes2
answers315
viewsProblem in a foreach
I’m using Laravel 5.3, and by making a foreach in the view, it does not recognize as an object, but if I print only what is in the variable $user it prints an object json. Controller: public…
-
3
votes2
answers319
viewsForeach with PHP Stdclass
My page shows posts that have been registered in the database. Some posts have files that have been uploaded. These files are saved in server folders and the database has the table "Archive" with…
-
3
votes0
answers195
viewsPHP with PDO returning BLOB records with foreach
Good afternoon guys, I’m new here (first question), but Stack has already helped me in several situations. That’s the problem: I am developing an application and on a given page there is a user…
-
3
votes0
answers138
viewsJquery Ajax - During upload - show real-time return date
I want the user to be able to track the progress of each shipment in an application. I have on one side, sending via ajax, and with php I perform a foreach for batch sending. For example, select id…
-
3
votes1
answer156
viewsmap.foreach Unexpected Return value
I have the following map: private static Map<ParseCreator, Parseable> map = new HashMap<>(); I walk this map as follows: for (Map.Entry<ParseCreator, Parseable> entry :…
-
3
votes1
answer649
viewsDiff between two commits
I’m making a git diff between two commits and in general it shows me the difference between the files that were modified in these commits. EX: git diff 1a1a1a 4d4d4d + Essa linha foi adicionada -…
-
2
votes4
answers3553
viewsHow to get the next element in a PHP foreach
How do I get the next element of an array using foreach? For example, I am iterating in an array and I need to know if the next element of this array is equal to what I’m doing to do some operation…
-
2
votes2
answers167
viewsUse substr directly on a foreach
My scenario is this:: foreach ($exibe as $u) { echo "<div class='col-md-3'><div class='thumbnail'> "; echo "<img src='{$u->imagem}' height='120px' class='img-thumbnail'>"; echo…
-
2
votes3
answers192
viewsProblem with variable concatenation
I have a variable in a foreach that picks up the registration id: $id_inscrito = $this->session->userdata('last_id'); I want to store this variable in another: $ids_ =…
-
2
votes2
answers186
viewsHow to make the id variable not repeat in the loop?
I’m trying to get one array associative as argument of this methods, actually receives a array in the first argument and a numerical value in the second. My question is how to make the variable $id…
-
2
votes2
answers1760
viewsHow to assign values to an associative array in php?
In an array, for example: $arr = array('item1', 'item2' ... 'itemN'); want to assign a value to each item. For this, I tried a foreach: foreach($arr as $a => $b) $b = 4; but is informed by the…
-
2
votes2
answers1825
viewsIncrement variable within a foreach
How do I make a variable increment within a foreach? foreach($adults as $adultos): $i = 1; echo "<strong>Quarto".$i++."</strong><br>"; echo "Adultos:".$adultos."<br>";…
-
2
votes2
answers168
viewsPHP - Foreach auto tuning
During development, it is often the case that a request is made to the database, in which the returned data comes in array, sometimes it is necessary to perform a foreach to adjust these data or…
-
2
votes1
answer1350
viewsHow to go through all the records in the database table?
Good afternoon, you guys! I’m starting in PHP and I already have a little problem. Is the following: I need to go through all the records in the bank table, so I can validate if such a value already…
-
2
votes1
answer10706
viewsHow to use foreach with this type of JSON (PHP)
I am trying to display the values of a JSON with PHP more unsuccessfully. Code Used: JSON { "friendslist": { "friends": [ { "steamid": "76561197960265731", "relationship": "friend", "friend_since":…
-
2
votes1
answer195
viewsHow to make a "for each" on Sqlite
I have an A table with n records. For each record of this table, I want to get information from a field x to make a select and, based on the results of select, make a insert in a table B. Only I…
-
2
votes3
answers8934
viewsHow to extract and list values from a multidimensional array?
I have this array: Array ( [Bairro] => Array ( [0] => Aberta dos Morros [1] => Camaquã [2] => Cavalhada [3] => Cristal [4] => Guarujá [5] => HÃpica [6] => HÃpica/Jardins…
-
2
votes2
answers758
viewsHow to create dynamic columns with Bootstrap and PHP?
I have 30 itens that will come in alphabetical order. I need to distribute these items in 3 columns in alphabetical order VERTICAL. The problem is that in Bootstrap, the blocks are marrying each…
-
2
votes2
answers1284
viewsForeach with lambda which returns the sum of iterated items
I’m trying to iterate on a List calling for produtos of objects called Produto, using the forEach, to obtain the sum of the values of these products using the lambda function of the forEach. But I…
-
2
votes1
answer479
viewsHow can I improve this loop that has one foreach inside another?
I’m making this code that has 2 foreach’s and carries 350 properties with more or less 3500 image links, I didn’t really call the photos, just the links, it all loads in half a second. The variable…
-
2
votes1
answer95
viewsValid times
I have a array with multiple schedules, may sometimes have only 4 and other N times. I just need to get some records. Follows my code: $array = array( 0 => "08:00:00", 1 => "08:02:00", 2 =>…
-
2
votes1
answer159
views -
2
votes2
answers110
viewsDoubt with loop of repetition
I am doing a series of exercises in PHP for practice. And I came across a question regarding the loop of repetition. To explain better I will put the statement of the exercise here: Efetue um…
-
2
votes2
answers82
viewsFilling Label with Linq using Tolist()?
I have a table with the following schematics: GarantiaImovel | imovelID | GarantiasTipos 12 | 3 | Caução2 12 | 4 | Depósito 12 | 5 | Caução2 12 | 5 | Fiador 12 | 5 | Seguro Fiança So I have the…
-
2
votes2
answers454
viewsInserting index and value into a two-dimensional array
I have a two-dimensional array (it contains data from the database). To go through this data, I use a foreach(). I need to add an index and a value to that index at the end of each foreach…
-
2
votes1
answer386
viewsForeach with 2 conditions
I’m trying to put two conditions on the foreach, but I’m not succeeding. The idea is as follows: the client accesses the site in the following URL: /room/balcony and appears only products that have…
-
2
votes4
answers3559
viewsIncrement a counter within a php foreach
In a bow tie foreach I need to increment a counter to set the tabindex of the form fields, so that the result is: <input type="text" name="endereco[0][cep]" value="00000-000" tabindex="1">…
-
2
votes2
answers1017
viewsMultiple insert with php PDO and Mysql
My situation, A post form with a text input and two radios inputs. Inputs are named respectively, nome[0] and tipo[0]. When one adds more form fields I put one .attr to stay nome[1] and tipo[1]" and…
-
2
votes1
answer238
viewsPerforming array validation within another array
I have the following array, when I give a var_dump(): array(2) { [""]=> array(10) { ["js/ultramegamenu.js"]=> string(19) "js/ultramegamenu.js" ["js/padoo/jquery.cycle.js"]=> string(24)…
-
2
votes1
answer58
viewsI can’t get into the foreach of a Lade at Laravel 5.7
I’ve got a little problem I haven’t figured out yet, I’ve got a View and I can’t get into foreach of the same, follows the View: <div class="form-group"> {!! csrf_field() !!} <!--{{…
-
2
votes1
answer123
viewsHow to compare responses and templates where each is a PHP string
I have 2 PHP strings that are the student’s responses and feedback. I need to compare them and show the result in a table: $respostas='1;A|2;B|3;C'; $gabaritos='1;A|2;B|3;D'; I need him to generate…
-
2
votes1
answer1915
viewsError: Collection modified; maybe enumeration operation is not executed
I have a problem using the foreach to traverse a array of strings. This component is a search button to select files, it selects and writes the address of the file into a array of strings, i created…
-
2
votes1
answer210
viewsTake the last value of an Array inside a Foreach
I’m making a foreach which brings the following database: $notificacoes = Notificacoes::where('user_id', $id) ->where('lido', false) ->orderBy('created_at', 'desc') ->get();…
-
2
votes2
answers209
views$. each on a JSON of cities
I am with a Json of cities in the following structure: var cidade = [ { "sigla": "AC", "nome": "Acre", "cidades": [ "Acrelândia", "Assis Brasil", "Brasiléia", "Bujari", "Capixaba", "Cruzeiro do…
-
2
votes2
answers328
viewsAssemble question and answer array
How do I mount this array, few times did foreach of unserialize, with that I’m having a hard time making this assembly. Model PHP <?php // $campoBD é a simulação do valor vindo do mysql pela…
-
2
votes1
answer101
viewsMPDF mounting with php foreach , bootstrap and html
I am trying to generate the MPDF, but this error appears: PHP Parse error: syntax error, Unexpected 'foreach' (T_FOREACH) This error is accusing in the second line that is the first foreach. $prova…
-
2
votes1
answer52
viewsCurious situation when entering grid-area with Javascript
I am inserting some stylizations in a little project that I am doing, and I have a foreach running in the DOM to go through a list, it turns out that if I add a grid-area and put the Dice as grid…
-
1
votes4
answers1855
viewsPHP/Codeigniter error "Array to string Conversion"
I did a foreach to go adding values to an Insert but suddenly an error appeared Array to string Conversion strange and have no idea what it is. public function distribuicaoprodutos(){…
-
1
votes2
answers674
viewsCan you use a variable that’s inside the for?
For example. I am working with Heredoc and whenever I need to do a for, I have to close Heredoc to do the for then open the mentioned tag again. Is there any way to query a variable within the is…
-
1
votes1
answer1195
viewsCodeigniter: retrieve values from the out-of-loop array
I’m having a problem storing the array values in the code below: public function get_submenu() { $query = $this->db->get_where('categories', array('category_id_parent' => 0)); foreach…
-
1
votes2
answers1507
viewsHow to display multiple error messages simultaneously in form?
I’m trying to get my log page to show all forgotten fields messages together as in this example: But it only shows in parts: 1 - "Username already exists" and "Email already exists" or 2 - "Please…
-
1
votes1
answer3080
viewsHow to use for each in array of arrays(array)?
Having the array of arrays: int matriz[][] = new int[1][1] How do I use for each (for(int Count : array)) to traverse your rows and columns?
-
1
votes1
answer366
viewsError with Foreach arguments
I created a structure with some loops however php is returning me that the foreach arguments are invalid... I’m not sure if this structure is correct, so I’d like someone to let me know if this is…
-
1
votes1
answer129
viewsHow to print array values
This is the xml used to generate the array <?xml version="1.0" encoding="utf-8"?> <integracao> <status>2</status> <resposta> <paginacao>…