Questions tagged as 'foreach'

2
answers

How to determine the last element of a list in a foreach?

Given any list, how do I know if foreach is in the last element? There are a few ways to do this, the most I can see is to save the last element and check if the current element is the same, but in that way it is necessary to check eve...
asked by 30.06.2016 / 16:07
2
answers

Show loop result in real time

I'm using a loop to send mail from an array. Each time the loop runs the sleep(4); function is executed. The problem is that the output of php only happens at the end, ie the echo "</br>n:".$ne."&nbsp".$user["email"]."<...
asked by 19.01.2016 / 17:14
1
answer

Loop overload with foreach use [closed]

Hello I'm having a serious problem at least and what the hosting company aqual this my site is claiming that my code below is overloading queries or doing several loops, and I do not know what else I can do. / p> Is there any way to unify or r...
asked by 13.11.2015 / 17:08
3
answers

Foreach Array by incrementing another array

With a question about foreach and incrementing another helper to perform an insert in the database, see: When I send a form via post I get the following array as a result: array (size=2) 'quantidade' => array (size=8) 0 =>...
asked by 14.11.2016 / 12:43
2
answers

Foreach inside foreach

I need to execute a foreach within another foreach in PHP. But it returns me the following error:    Parse error: syntax error, unexpected T_FOREACH referring to the line where the second foreach occurs Here's part of the...
asked by 02.04.2015 / 20:29
2
answers

Return with all the lines of the foreach

I have the following script : <?php $recursos_data = array( array( "id" => "0", "recurso_nome" => "madeira", "producao" => "%produz%", "estoque" => "200"...
asked by 28.10.2014 / 00:22
2
answers

How to loop with while using array

Hello, I would like to know if it is possible to loop using while so I need the values of the $newsmedias1 array to be placed in while in order to make the appearance of the items with the given IDS in the Array as lo...
asked by 22.10.2015 / 15:41
5
answers

Use if inside foreach

I am trying to change the order in which the results appear within a loop using foreach. What I need is for numbers greater than five to appear first, followed by the rest of the numbers. So I tried something like this: $numeros = array(1, 2,...
asked by 09.05.2014 / 19:47
3
answers

INSERT Query does not work inside a loop

So folks, I'm not able to solve this problem of a query inside a foreach loop does not execute. First of all I thought it was something wrong with pdo-> beginTransaction so I commented this part and left pure code only. <?php if (is...
asked by 10.08.2014 / 01:31
3
answers

What is the difference between foreach uses in php?

What is the difference between these two means of using foreach in php? Would one be more special than the other, bringing some advantage for example? Method 1: foreach ($arr as $key => $value) { #do something } Method 2:...
asked by 03.11.2016 / 02:34