Questions tagged as 'foreach'

1
answer

Using Foreach in PHP

The foreach constructor provides an easy way to iterate over arrays . In several scripts we can observe the following usage: foreach ($array as $value) { $value = $value * 2; } However, in some cases the following use is possibl...
asked by 16.06.2017 / 16:41
1
answer

How to create foreach (PHP / SQL)

I'm trying to send from a form to html, a table, with two fields with Array[] . These two fields are Service and Value, I want to add more than one product in form , and it inserts into different records in my table. I did...
asked by 26.04.2016 / 21:51
1
answer

Foreach PHP JSON json_decode How to print sub array

Good morning everyone! My question is as follows. I created a foreach to access the data below an API $token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $headers = array('Authorization: Token ' . $token); $ch_subs = curl_init(); curl_setopt($ch_subs...
asked by 07.09.2018 / 12:14
2
answers

Label in loop in Foreach

I'm having difficulty displaying information that comes from an object to show on a Label, returning it as a list. //Pegando os dados do Rest e armazenando na variável usuários var usuario = response.Content.ReadAsAsync<IEnumerable<Cons...
asked by 27.07.2018 / 14:59
2
answers

Remove comma from the last foreach value in PHP [duplicate]

Good morning, I have a foreach in my system and I need to separate the pro comma items, so the foreach is like this foreach($value as $item){ echo $item . ','} The result obviously comes out: 1,2,3, How do I get this last comma, r...
asked by 05.09.2016 / 16:04
2
answers

Foreach Duplicating Data

I have 2 foreachs , to do a date search in ViewBags , where I return both in a select. But for each item in the first foreach, it makes a full loop in the second, thus doubling the values, by each item in the first. Ex: If I ha...
asked by 02.02.2015 / 12:56
4
answers

foreach php inside script

Could you please let me know if it is wrong to use this code like this: <script type="text/javascript"> <?php foreach ($lista as $key => $value) { $id_indicador = $lista[$key]['id']; ?> var id_indicador = <?php echo $i...
asked by 11.11.2015 / 16:34
2
answers

Problem in a foreach

I'm using Laravel 5.3 , and when doing a foreach in the view, it does not recognize as an object, but if I print only what is in the $user variable it prints a json object %. Controller: public function getAll() { retu...
asked by 08.11.2016 / 12:17
1
answer

Foreach behavior with variables by reference

I was doing some testing and I noticed that foreach behaves oddly. Suppose I have the following array : $array = array('primeiro', 'segundo', 'terceiro'); When I run a foreach using a reference, and then another forea...
asked by 14.08.2015 / 18:18
1
answer

Can you have some error in foreach execution in this method?

Can I run the following code in error? protected void ImprimeValores(Ilist<int> values) { if (values.Count > 0 && values != null) { foreach(int v in values) Console.WriteLine(string.Con...
asked by 22.05.2016 / 20:14