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
-
5
votes3
answers9803
viewsPassing array as a function parameter
I want to receive the array containing numbers 3, 15 and 23 and array output display double. Only it is giving the following error: Warning: Missing argument 1 for criando_array(), called in…
-
5
votes1
answer70
viewsInsert into array, whose parent property value is equal to the property value of the child object
I have an object (Questions) and I want another object (Answers) to be added to it according to a common id. var Perguntas = [ { idPergunta: 13, textoPergunta: "Qual seu nome" , Respostas : [] }, {…
-
5
votes3
answers389
viewsCompiler error when trying to reset vector
Compilers error when I try to reset an array with the command vetor[10] = {0}; And he only makes a mistake in that line because I also used it in the assignment int vetor[10] = {0} and there does…
-
5
votes1
answer9847
viewsHow to create string vectors in java?
"Make an algorithm to receive an integer n (number of students), an integer m (number of subjects), and nxm grades from 0 to 10, which each student obtained in each discipline. Present: a) which (or…
-
5
votes1
answer4267
viewsConvert JSON to Array in Javascript
Good afternoon, it’s my first question here. I’m getting the json below through an ajax request. [ {"SEMANA":1.0,"PRODUCAO":0.0,"PRODUCAO2":0.0},…
-
5
votes3
answers1630
viewsMount a single string with multiple strings from a Java Arraylist
How can I take several Strings of an Arraylist in a simplified way and join in only one String type variable? I’m new to Java and I’m having difficulty completing this change in a simplified way,…
-
5
votes1
answer781
viewsHow to save data to a global array
I am studying PHP, and so far I have developed a small system that "mounts" the site views and etc. But I came across an extremely annoying problem that I can’t solve. I need a function to show the…
-
5
votes1
answer2070
viewsJava Arraylist - Overriding values
Guys need to perform the following activity: "Consider an application to store the following data of a person in an address book: name, address, and phone. Specify a TAD to store the data of persons…
-
5
votes2
answers1050
viewsHow to order numbers from an array?
I do not find the function to sort, increasingly, the numbers drawn. <?php $resultado = array(); for ($i = 0; $i <= 5; $i++){ array_push($resultado,rand(1,60)); } print_r($resultado); # Exibe…
-
5
votes4
answers199
viewsProblem accessing array element
I have a problem in the function below that truncates all words to have at most N characters. For example: if the string "freedom, equality and fraternity" means the invocation of truncW(t,4) should…
-
5
votes5
answers3336
viewsHow to mix an array in Javascript?
In PHP, when I need to mix an array, I use the function shuffle. Thus: $a = array('@wallacemaxters', '@rray', '@CiganoMorrisonMendez'); shuffle($a); print_r($a); exit: Array ( [0] =>…
-
5
votes1
answer1926
viewsHow to declare and initialize two-dimensional matrices?
I have to save the row, column and contents of a spreadsheet. For this I created a two-dimensional matrix. My difficulty is how to initialize it? I believe the statement is no longer correct because…
-
5
votes3
answers742
viewsHow to check if a value is present within an array?
$idofdb = "25"; $myArray = array(); foreach ( $fthi as $codigo ) { $myArray[] = $codigo['ImoCodigo']; } $checkValues = array_values($myArray); $checkString = implode(',', $checkValues); //…
-
5
votes2
answers431
viewsCount elements in a range of values
Is there any more concise way to count all the elements of a vector (here in the example between 10 and 20) than the one presented? vector<int> v={1,2,3,45,24,10,20,-90,100,18,17,15,87}; int…
-
5
votes1
answer169
viewsSpecial treatment for string, why?
I know arrays are static elements used when you have a predetermined size that you can use. But speaking of initialization, when the size is already set next to the array, I would like to know,…
-
5
votes3
answers1915
viewsRemove element from a vector in C# and don’t leave the vector with a blank space?
I need to remove an element from a vector with 5 elements, and cannot get empty space in the vector. I need to remove by index.
-
5
votes2
answers859
viewsInvert array (vector) without an external function, 'manually'
Friends, I always invert vectors using an auxiliary in an external function (I think the standard way), however until recently a friend told me that had a way to invert vectors without using an…
-
5
votes2
answers182
viewspreg_split is not breaking the strings in the array
I’m not getting to use the function preg_split() correctly. I’m trying to break a string array() via regex but it’s not happening. $string = "<:termo.9:><:termo.10:><:termo.11:>";…
-
5
votes2
answers180
viewsWhy does the statement "char *argv[]" work in the main rg, but not in the body of the code?
Why when I use the declaration char *argv[] in the int main(int argc,char *argv[]) works, but when I try to use it inside the body of the code with char *argv[]; it doesn’t work? The error below is…
-
5
votes2
answers1792
viewsJson output with json_encode()
json_encode() - Returns the JSON representation of a value If I do: $foo = array('a', 'b', 'c', 'd', 'e'); echo json_encode($foo); I’ll get: ["a","b","c","d","e"] So far so good, I’m taking an array…
-
5
votes3
answers885
viewsHow can I check if the last position of the array has been filled?
How can I check if the last position of the array has been filled? I tried the function array_pop but it seems she cuts the element of array, I just want to check if in the last position of array is…
-
5
votes1
answer558
viewsHow to access the indexes of a very large vector in C?
I have a problem that I have to assemble a vector (vet2[50]) with the sum of a large vector (vet1[100]), this vector vet1 is provided by the user and the sum if provided by: vet2[0]=vet1[0]+vet1[1]…
-
5
votes1
answer116
viewsIn a repetitive structure are there differences between working with Object or Array?
When I do a query in the database by PHP and want to return this data with while, usually use the fetch_object(), which returns the data in type object. For example: $query = "SELECT * FROM TABELA";…
-
5
votes7
answers2833
viewsHow to check if at least one item of the array has value equal to or greater than 2
I have the following array: array[0,2,0,0]; I need to create a function that returns me true if at least one array item has value equal to or greater than 2
-
5
votes1
answer107
viewsWhy is it possible to access array indexes with "{}" keys?
In some tests I did with PHP, I saw that it is possible to use keys ({}) to access indexes of arrays. Example: $array = ['a' => 1, 'b' => 2, 'c' => ['d' => 4]] echo $array{'c'}{'d'}; //…
-
5
votes2
answers4626
viewsHow to compare the content of two vectors?
public class VetorTurma { public static void main(String[] args) { int pontuacao = 0,nota,c; String nome; Scanner sc = new Scanner(System.in); double gabaritoVetor[] = new double[10]; double…
-
5
votes2
answers393
viewsIf array is the same as pointer, why does one need to be copied to a variable and another need not?
In that reply Maniero said that if the member of the structure was a pointer it would not need to copy the string into it. But arrays are not pointers? Why is it different?…
-
5
votes2
answers866
viewsChar pointer or char array?
There’s a program that I picked up at a company, where pointers are used to char, guy char*, and then allocated a memory for it with the malloc, done the operations and at the end de-located that…
-
5
votes3
answers1419
viewsWhat is the difference in checking an array with isset and array_key_exists?
In PHP we often have more than one way to do the same operation. A basic example is in verifying the existence of a given index in a array: we can use array_keys_exists. Example: $arr = ['a' =>…
-
5
votes4
answers819
viewsHow to make a function to tell when an array is empty?
I need a function that lets me know when an array is empty, function validaCampo(){ if(count(dias[])==0) { alert("O Campo Dias disponíveis é obrigatório!"); return false; } else return true; }…
-
5
votes2
answers340
viewsHow to create an array whose indices are characters from an informed string?
I wanted to create a vector in java in which each input of the vector was a character of a string that I informed public static void main(String[] args) { String[] words = {"java"};…
-
5
votes2
answers7910
viewsRead text file and play the content in positions in an array!
I’m not sure I can read a file .txt and store your data in different positions in one array. The file is saved as follows: city=A(100,80); city=B(160,70); city=C(110,50); city=D(140,120);…
-
5
votes1
answer117
viewsHow to use a variable in the array_walk?
I’m trying a solution without going through "manually"(foreach) an array, to add in the subarrays, a new pair of chave => valor. With the array_walk I can invoke a callback and treat the array…
-
5
votes2
answers572
viewsDifference between Compact function and literal array assignment
According to the PHP documentation, the function compact. For each of the parameters passed, compact() looks for a variable with the name specified in the symbol table and adds it in the output…
-
5
votes2
answers1518
viewsAPI of Mercadopago
I’m making a trolley system here to test the API of the marketplace. Everything is working, except the part about creating the payment that I have no idea how to get started. API Mercadopago I’m not…
-
5
votes2
answers939
viewsGenerate a random profession for Online Players
I am creating a small game (Android) to play I more friends of mine. The game is called "Cops and Thieves". At least it is necessary to have 4 players in which one of them will be the POLICE,…
-
5
votes3
answers718
viewsAssign values to arrays
I realized that by increasing a value to one array using the following syntax: let array = []; array['nomeIndice'] = 10; the length that array is not incremented, and continues in 0, despite the…
-
5
votes2
answers933
viewsTake the index of a value in an array
How do I get an index of a value of mine array? For example: char[] letras = new char[]{'a','b','c','d'}; In letras, i would like to pick up the value index b for example. How do I do this in C#?…
-
5
votes3
answers543
viewsHow to display a multidimensional array without looping?
When trying to run the section below: int[] vetor = {1, 2, 3, 4, 5, 6}; System.out.println(Arrays.toString(vetor)); The array is normally displayed as [1, 2, 3, 4, 5, 6] but if I try with a…
-
5
votes2
answers446
viewsHow to take 2 PHP arrays and join in 1 string
I have 2 PHP arrays that come from a form $_POST['qtd'] and $_POST['ing']: array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } array(2) { [0]=> string(1) "a" [1]=> string(1) "b" } It…
-
5
votes2
answers498
viewsHow to make mobile sum in R?
I have a vector 1:50 and need to perform a moving sum (equal to moving average), that is, in the case of the last 5 observations, the new vector would be c(sum(1:5), sum(2:6), sum(3:7), ...,…
-
5
votes2
answers49
viewsExtract vectors from a vector set of vector names and merge into a single vector
I have a vector that contains names of other vectors. For example: teste [1] "vetor_arte" "vetor_rio" "vetor_parque" vetor_arte [1] 1 3 4 11 12 13 14 16 29 30 41 vetor_rio [1] 6 7 8 9 10…
-
5
votes1
answer215
viewsComparison of value within data frame
Hello, I have a database, with about 50000 remarks, as follows, only figurative values: nome<-c("joão","pedro", "joãoo") identificador<-c(123456,124578,123456) valor<-c(2145,350,23)…
-
5
votes2
answers180
viewsIncorrect value in vector when binary search
import java.util.Arrays; /** * @author Vinicius * */ public class Vetor04 { /** * @param args */ public static void main(String[] args) { int vet[] = {3, 7, 6, 1, 9, 4, 5}; int s =…
-
5
votes1
answer803
viewsGetting information from an array within a foreach - PHP
Good afternoon. I’m developing a PHP application using Laravel, and I’m having a hard time. I have a table with the Account name, which has the code of this account, represented by the variable…
-
5
votes1
answer219
viewsIs it incorrect (or problematic) to create a string array struct?
I’m not sure what’s the ideal way to create a structure (struct) that contains a array of string, in case I have a structure like this: #include <stdio.h> #include <stdlib.h> typedef…
-
5
votes3
answers97
viewsWhy does the first element of the vector come out as zero without having stored this value there?
Why the following code prints a 0 at the beginning of the output? #include <stdio.h> #include <limits.h> // Escreva um programa que leia do teclado 8 valores, e em seguida os // imprima…
-
5
votes1
answer73
viewsstruct character array
I’m having to remember programming in c++ to teach a beginner class in programming logic. Subject that I haven’t seen in years. One struct was declared however when entering a string, the stream…
-
5
votes5
answers713
viewsindexof does not find element in an array
The indexOf() is returning me -1 even though I have this element, I am doing so: pessoas = []; pessoas.push({"nome": "Pedro"}) pessoas.push({"nome": "João"}) pessoas.push({"nome": "Maria"})…
-
5
votes2
answers1771
viewsLogic for grouping data in javascript array
I’m having trouble grouping some data using the Javascript. I have the following array of objects that return from database and shipping to the view: var object = [ { data: 1, categories: "Branca",…