Questions tagged as 'foreach'

4
answers

How to get the next element in a foreach in PHP

How do I get the next element in an array using foreach? For example, I'm iterating in an array and I need to know if the next element in this array is the same as what I'm about to do some operation against it.     
asked by 16.10.2014 / 01:59
2
answers

Use substr directly in a foreach

My scenario is as follows: foreach ($exibe as $u) { echo "<div class='col-md-3'><div class='thumbnail'> "; echo "<img src='{$u->imagem}' height='120px' class='img-thumbnail'>";...
asked by 28.12.2014 / 22:18
5
answers

How to get index of the current iteration of a foreach?

Normally, in order to get the current iteration index within a foreach , I do this: int i=0; foreach (var elemento in list) { // Qualquer coisa i++; } I believe there are other methods to get the iteration index (even mo...
asked by 06.09.2016 / 03:43
2
answers

Increment variable inside a foreach [closed]

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>"; endforeach;     
asked by 19.09.2017 / 01:51
2
answers

How 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] =...
asked by 03.01.2016 / 03:19
1
answer

Foreach jquery concatenate in table

I have an AJAX that in success brings a response : $(response).each(function(i) { alert(response[i]); $('#tbody').html( "<tr>" + "<td>" + response[i].id + "</td>" + "<td>" + respo...
asked by 31.10.2018 / 14:41
3
answers

Traversing array of objects and accessing a value

Good afternoon, I have a difficulty, where I need to access an element of an array of OBJECTS, I'm not able to access with the foreach, or for. I need your help! The array of objects: Array ( [0] => stdClass Object (...
asked by 11.10.2016 / 15:56
2
answers

Go through dates by printing a field for each one

I'm making a system a bit like a calendar / schedule. In it I have a semestre table that has a data de incio field and a data fim field and I need to scroll through those dates by printing the name of each day in the head...
asked by 25.10.2014 / 22:20
2
answers

Doubt with repeat loop

I'm doing a series of exercises in PHP for practice. And I came across a question regarding loop repetition. To explain it better I'll put the exercise statement here: Efetue um algorítmo PHP que receba dois valores quaisquer e efetue sua mult...
asked by 22.05.2017 / 20:14
1
answer

How to do a "for each" in SQLite

I have a table A with n records. For each record in this table, I want to get the information from a x field to make a select and, from the result data of this select , make a insert on a table B. Only that I need to do t...
asked by 12.06.2018 / 20:34