[Solved] PHP add counter to name if already exists in array

$arrayOfNames = array( array(‘clientName’ => ‘John’), array(‘clientName’ => ‘John’), array(‘clientName’ => ‘Mary’), array(‘clientName’ => ‘Mary’), array(‘clientName’ => ‘Mary’), array(‘clientName’ => ‘Tony’), array(‘clientName’ => ‘Alex’) ); $namesCount = array(); $finalNames = array_map(function ($item) use (&$namesCount) { if (!isset($namesCount[$item[‘clientName’]])) { $namesCount[$item[‘clientName’]] = 0; } $namesCount[$item[‘clientName’]]++; $item[‘clientName’] = $item[‘clientName’] . ‘ ‘ . $namesCount[$item[‘clientName’]]; return $item; }, $arrayOfNames); … Read more

[Solved] setting the size of array

According to your error messages, you compile with a C++ compiler. Do not! C is not C++ and C++ is not C with classes. They are different languages. As the messages state, C++ does not provide VLAs (see below). Use a standard-compliant C compiler, or at least a C99 compiler. Variable length arrays (VLAs) were … Read more

[Solved] Parse array of elements

#Updating code snippet by leplatrem result = {’44’: [‘2’, ‘4’], ’41’: [‘1’, ‘2’, ‘3’]} for (k,v) in result.viewitems(): temp_list = [str(i) for i in v] temp_str = “,”.join(temp_list) temp_str = “‘” + temp_str + “‘” print “UPDATE myTable SET myColumn={} where id={}”.format(temp_str,k) #Output UPDATE myTable SET myColumn=’2,4′ where id=44 UPDATE myTable SET myColumn=’1,2,3’ where id=41 … Read more

[Solved] How to take average of number of values greater than some value in array? [closed]

public static int isGreater(int limit, int[] data){ int overLimit = 0; for(int k = 0; k < data.length; k++){ if (data[k] > limit) overLimit++; } return (overLimit/data.length)*100; } By keeping a running calculation of the numbers that are over and under the limit, you can calculate what percentage of the overall list was greater than … Read more

[Solved] Notice: Array to string conversion ERROR [closed]

First you need to change: foreach ($traits[$i] as $trait) To: foreach ($traits as $trait) Then realize that $trait is still an array. So instead of echo ‘<BR>’.$trait, $test, $i + 1; You want to still loop through that array: foreach($trait AS $value) Now you can echo out your $value foreach ($traits as $trait) { foreach($trait … Read more

[Solved] array inside function

#include<stdio.h> #define MAX_SIZE_ALLOTED_TO_EACH_QUESTION 100 #define NUMBER_OF_QUESTIONS 10 int scoreList[NUMBER_OF_QUESTIONS]; // This array will contain the individual score for each answers to respective questions int i; void Extroversion(int scoreList[]){ // Let formula for this be E = 20 +(1)___-(3)___+(2)___-(4)___ int E = 20 + (scoreList[1] + scoreList[2]) – (scoreList[3] + scoreList[4]); printf(“\nExtroversion is the personality trait … Read more

[Solved] I keep getting java.lang.ArrayIndexOutOfBoundsException: 5! How do I fix this? [closed]

Based on what you’ve shown: testNum is greater than scores.length. This means that when you traverse the array by comparing your iterator (i) to testNum rather than its actual length, you will hit indexes which don’t exist. For example, let’s say testNum = 8 and scores.length = 5. Then in your code, you will get … Read more

[Solved] How do I compare chars (or strings) using void functions, also comparing chars that were taken from a struct array

If I understand you correctly, you have a structure containing several members of different types and you are looking for a way how you could compare instances of this struct. It could look the following way: struct X { std::string s; char c; int i; bool operator==(const X& ref) { return s == ref.s && … Read more

[Solved] How to multiply two matrices having fractions as inputs in c [closed]

I wanted to use my own implementation of the Strassen optimization for matrix multiplication. It is highly optimized and hence has almost no pedagogical use but then I remembered that Wikipedia has actual C code in the Strassen-matrix-multiplication entry. The implementation there is not the best: it has no fallback to the naive algorithm if … Read more