Most voted "array" questions
An array (array, vector, or matrix) is an ordered data structure representing a collection of elements (values or variables), each identified by one or multiple indices.
Learn more…3,046 questions
Sort by count of
-
4
votes1
answer1274
viewsWhat is the difference between array_walk and array_map?
In PHP, we have two functions that traverse the array and apply a function determined for each element: array_walk and array_map. Example: $meu_array = array(1, 2, 3); $callback = function ($value)…
-
4
votes2
answers715
viewsAdd the 5 highest values to an array
I have the following method: public static void topFiveSales(int idEmpresa) { List < Entidade > allList = Entidade.findByEmpresa(idEmpresa); float totalVendasByEntidade; Float[] totais = new…
-
4
votes2
answers183
viewsNested Vector Logic - C++
I have a problem with the following statement: Given a vector A with n real numbers, obtain another vector B, also with n real numbers, as follows: B[1] = 2*A[1] B[2] = 3*A[1] + 2*A[2] B[3] = 4*A[1]…
-
4
votes2
answers5070
viewsHow to display a certain position of an associative array?
This is my array associative: $vetor = array( "Nome"=> "posicao1", "Telefone"=> "posicao2", "Idade"=> "posicao3", "Sexo"=> "posicao4" ); To display its contents I can use the foreach();…
-
4
votes1
answer136
viewsIs it possible to know if a two-dimensional array is empty?
basically my doubt is already clarified in the question. That’s it, I wonder if it is possible to know if a two-dimensional array is empty? Thank you in advance!…
-
4
votes6
answers201
viewsHow to remove 2 digits from each item in the list?
I have a list/array: var lista['01.um','02.dois','03.tres'] I need to create a new list like this: lista['01','02','03'] I know little of Groovy and Java, which is the correct way to create the…
-
4
votes2
answers102
viewsSort method is not ordering correctly
I have the following code: #include <bits/stdc++.h> using namespace std; int main() { int n, cases = 1, a[3]; cin >> n; while(cases != n + 1) { cin >> a[0] >> a[1] >>…
-
4
votes2
answers1683
viewsHow to sort this php array?
I have this array: $res = array(); $res[] = array("16/08/2013", "13:32", "ROBERTO"); $res[] = array("16/08/2013", "13:16", "AMANDA"); $res[] = array("14/08/2013", "12:36", "SILMARA"); $res[] =…
-
4
votes3
answers2804
viewsComparing an array element with a string
I need to create a function that receives a array and compare with a string, outside the array, returning true if, and only if, there is at least twice the occurrence of string outside the array.…
-
4
votes2
answers1491
viewsStore some elements of an array in another array
I have defined a array integer in which it will be pointed by a pointer and then I have another array which will store only a few numbers in which are even numbers, here is the code... void…
-
4
votes3
answers820
views -
4
votes1
answer469
viewsHow to extract only different values from an array?
I’m extracting from a array city names. I want to extract cities with different names. In the current case, my script returns several identical city names. I want to recover only once each city…
-
4
votes5
answers3614
viewsSplit array into smaller groups
I have an array in this format: meuArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ...]; I would like to turn it into a multidimensional array with javascript/jquery leaving it so:…
-
4
votes0
answers102
viewsCreate an array/Arrays based on a TXT file
I am new to using the Fortran/95 language and want to extract some data from a txt file (http://1drv.ms/20gSNKb), are flow data available in the Hidroweb portal. Whereas they are separated by ";" as…
-
4
votes2
answers4557
viewsHow to compare two arrays and return the difference between them?
I have 2 arrays that come from 2 different banks, one comes from sql server other mysql. The Mysl query returns like this.. array (size=6) 0 => string 'ultimoteste3' (length=12) 1 => string…
-
4
votes1
answer1041
viewsWhat is the elegant way to read this PHP Object?
I have the Result of a Webservice below, I’m doing a "foreachs" to read each level of the Class, but I think it should have a more elegant way to read and get the values of the object, follows the…
-
4
votes2
answers333
viewsCalculate minimum number of permutations to sort
I received this question in a test, and I would like to know which ways to go. I have an array of distinct n integers, A = [A0, a1, ..., an-1]. I can swap any two elements of the array any number of…
-
4
votes1
answer2537
viewsWhat is the difference between pointer to vector and pointer to variable?
int A; int* pA = 1; int Vect[2] = {1,2}; int* pVect; pA = &A; *pA = 2; pVect = Vect; pVect[0] = 10; In the case I have a pointer to a variable and then to an array, and I want to change its…
-
4
votes3
answers88
viewsMerge array as PHP
I have it: $categoria_1[0] = array( 'code' => 'ALI000001', 'name' => 'Alimento > Arroz ); $categoria_2[0] = array( 'code' => 'ALI000002', 'name' => 'Alimento > Massas ); And I need…
-
4
votes1
answer475
viewsWhat is the difference between array_replace and array_merge?
I wonder what the difference is between array_replace and array_merge, because in some cases the two seem to have similar behaviors. Example: $informacoes = ['nome' => 'wallace', 'idade' =>…
-
4
votes3
answers6684
viewsHow to create a dynamic variable
I have a field(input text), and would like to get the value, and pass as variable. In other words, pass the value of this text field into the: var valor do campo aqui ; See the example I leave:…
-
4
votes2
answers6177
viewsHow to insert index and element within an array
I’m developing a loop to compare two tables in a database. The purpose is to know how many people were appointed by the same employee of the company. For this, I need to start a array as follows:…
-
4
votes2
answers142
viewsHow can I format this array to the way I want it?
I’m creating a Seeder to the Laravel insert values into a table N para N. I am riding the array in one way, but I need it to "become" in another. This is because I want to avoid repeating constant…
-
4
votes1
answer114
viewsarray 1D for Bitmap
I’ve been working on an FPGA project that sends an array (1D) of Bytes from a grayscale image to the PC. Well, I wrote a simple code with some image to simulate sending and receiving an array and…
-
4
votes1
answer7212
viewsPass Array as a function parameter
Make a program in C that reads a value x, dynamically create a vector of x elements and pass this vector to a function that will read the elements of this vector. Then, in the main program, the…
-
4
votes2
answers109
viewsWhy is 8 showing up and not the number referring to i?
<style> .menu > li:hover .sub-menu{ display:block; } </style> <ul class="menu"> <li>li 1</li> <li>li 2</li> <li>li 3 <ul class="sub-menu">…
-
4
votes4
answers20854
viewsHow to order vector in descending order?
How do I place a vector in descending order? public static void vetor() { int[] vet = { 7, 4, 10, 8, 2, 5 }; Arrays.sort(vet); //Comando para colocar em ordem decrescente. for (int i = 0; i <…
-
4
votes1
answer505
viewsSearch Matrix index from json value using the index
I have the following matrix: var usuarios = [ {nome: "João", id: 1}, {nome: "Maria", id: 2}, {nome: "José", id: 3}, {nome: "Ana", id: 4}, ]; I need to return the José user index. I tried using the…
-
4
votes1
answer150
viewsCreate an instance of jQuery from an array
I have the following array: var elementos = [$("#elemento1"), $("#elemento2"), $("#elemento3")] I need to create a function that "converts" this array into a jQuery instance, so I can use jQuery…
-
4
votes1
answer357
viewsDifferences between Python and Javascript in relation to arrays?
I’m having some difficulty because in Javascript it was possible to do this: const x = [] x[0] = 1 x[1] = 2 But in Python when I create an empty list and try to make a statement it says that the…
-
4
votes2
answers842
viewsUsing Array.Foreach to modify the collection
I want to remove spaces from the beginning and end of the string (Trim) in all positions of array, but none of the ways below worked. What am I doing wrong? var optionArray = new string[] { "in the…
-
4
votes0
answers40
viewsDifference in Javascript array declaration
What is the difference between these two forms? var a = []; var a = new Array();
-
4
votes1
answer567
viewsHow to convert array keys to all uppercase or lowercase?
I’m getting some data from a Webservice, through a JSON response. Convert this data from JSON to array, through json_decode. But one thing that’s bothering me is the fact the keys are coming with…
-
4
votes1
answer5565
viewsHow to remove an item at an array position?
Example: string[] x = {"3","2","1"}; I just want to take off the item "2" array x, resulting in: x = {"3","1"};…
-
4
votes3
answers1317
viewsRemove duplicate values from an array - php
I need to remove duplicate values from a PHP array, for example: $array = ('2015', '2015', '2012', '2013', '2014', '2014', '2016') I wish I had the output: Array ( [0] => 2012 [1] => 2013 [2]…
-
4
votes3
answers510
viewsHow to make an error message for this situation?
arq=open('filmes.txt','r') filmes = arq.readlines() def buscaPorGenero(): genero=str(input("Digite o gênero do filme: ")) while(True): for linha in filmes: linha = linha.split(";") if genero in…
-
4
votes1
answer192
viewsWhat is the difference between using Arrayiterator vs Simple Array?
Some examples on the net with ArrayInterator is used in the following ways:: $arr = array("Banana", "Abacaxi", "Abacate", "Morango"); // loop through the object foreach (new ArrayIterator($arr) as…
-
4
votes1
answer155
viewsArray and type being created
In Java, when I have the following instruction: int[] ns = new int[5]; the following doubts arise: An object of what type is created? For each value in an index, I call it an instance?…
-
4
votes1
answer100
views -
4
votes1
answer116
viewsHow to pass an array in a WHERE condition
$this->db->set('al_reg', $matricula); $this->db->set('dataagendamento', $dataagendamento); $this->db->where('cod_lab', $laboratorio); $this->db->where('cod_horario',…
-
4
votes1
answer941
viewsHow to transform Array into distinct variables?
I have the following array that returns me the following values: ( [cliente] => Array ( [0] => Array ( [Code] => 1 [Name] => a ) [1] => Array ( [Code] => 2 [Name] => b ) ) )…
-
4
votes1
answer496
viewsArray in PHP using () or []?
I always use the parentheses to define an array in PHP, such as: $array = array('a','b','c'); But once in a while I see some codes here using brackets, like: $array = ['a', 'b', 'c']; However, if I…
-
4
votes2
answers73
viewsCreating an array from two
I have the situation where I need to build in java a arrayC[] from a arrayA[4] and a arrayB[7], where the arrayC[] should present in order the arrayA[4] and then the arrayB[7]: for example:…
-
4
votes2
answers59
viewsUnusual way to use a jquery function
This answer to a question brought something I didn’t know: a return with two pairs of square bracketsreturn[][] in a role, solving a problem in a simple but unknown way to me. The question called…
-
4
votes1
answer101
views -
4
votes1
answer38
viewsIs there a way to do these assignments more cleanly?
I have a class that should be started with a array property. $subscription = new CheckRenew([ 'custom_2_id' => 13, 'email' => '[email protected]', 'zip' => '90530000', 'number' =>…
-
4
votes1
answer224
viewsHow to add values to an array of a Ruby array?
puts "Alunos\n\n" alunos = [["Daniel: ", "Nota: 10\n\n"],["Abima: ", "Nota: 10\n\n"], ["Wilame: ", "Nota: 10\n\n"],["Felipe: ","Nota: 10\n\n"]] puts alunos I wonder if it is possible to add a new…
-
4
votes2
answers1511
viewsCipher de Vigenere
private static void algoritmo(String input, String chave, Boolean b) { Console.WriteLine("Digite a mensagem: "); input = Console.ReadLine(); Console.WriteLine("Digite a chave: "); chave =…
-
4
votes3
answers3702
viewsNotice : Array to String Conversion in
I have a problem with the following code : <select name="tipoPessoa" class="form-control"> <?php $tipos = array("Pessoa Fisica","Pessoa Juridica"); $tipoSemEspaco = str_replace("…
-
4
votes3
answers609
viewsHow to compare 2 Arrays to Assert.Equals?
I need to compare two arrays on Assert.Equals. When I test the method in race it is right but the test does not pass. Code: public void SeparaStringTest() { RecebeComando recebecomando = new…