Snippets tagged “array”
105 snippets use this tag.
- A quick and easy way to join array elements with a separator (the opposite of split) in JavaJava
To join array elements with a separator in Java, you can use the join method from the String class.
- Add data dynamically to an ArrayPHP
To add data dynamically to an array in PHP, you can use the $array[] = $value syntax.
- array_push() with key value pairPHP
To add an element to the end of an array with a key-value pair in PHP, you can use the array_push() function.
- Best way to document Array options in PHPDoc?PHP
When documenting an array option in PHPDoc, you can use the @var tag followed by the type array and a short description of the option.
- Check if all values in array are the samePHP
In PHP, you can use the array_unique function to check if all values in an array are the same.
- Convert flat array to a delimited string to be saved in the databasePHP
You can use the implode() function to convert an array to a delimited string in PHP.
- Convert list to array in JavaJava
To convert a List to an array in Java, you can use the toArray() method of the List interface. This method returns an array containing all of the elements in the list in the proper order.
- Convert multidimensional array into single arrayPHP
To convert a multidimensional array into a single array in PHP, you can use the array_merge() function.
- Convert pandas dataframe to NumPy arrayPython
In pandas, you can convert a DataFrame to a NumPy array by using the values attribute.
- Create Array from ForeachPHP
To create an array from a foreach loop in PHP, you can use the array push function array_push() inside the loop.
- Display an array in a readable/hierarchical formatPHP
Here is an example of how you could display an array in a readable/hierarchical format in PHP:
- Explanation of 'String args[]' and static in 'public static void main(String[] args)'Java
In the main() method in Java, String args[] is an array of strings that holds the command-line arguments passed to the program.
- Get only part of an Array in Java?Java
To get only a part of an array in Java, you can use the Arrays.copyOfRange() method, or you can use the System.arraycopy() method.
- Getting the array length of a 2D array in JavaJava
To get the length of a 2D array in Java, you can use the length field of the array.
- Group array by subarray valuesPHP
In PHP, you can group an array of arrays (subarrays) by the value of a specific key in each subarray using the array_reduce() function.
- How can I check if an array element exists?PHP
In PHP, you can use the "in_array" function to check if an element exists in an array.
- How can I print all the values of an array?PHP
In PHP, you can use a foreach loop to iterate through an array and print each value.
- How can I trim all strings in an Array?PHP
You can use the array_map() function to trim all strings in an array in PHP.
- How do I declare and initialize an array in Java?Java
There are several ways to declare and initialize an array in Java. Here are a few examples: Declare and initialize an array of integers with size 5
- How do I initialize a byte array in Java?Java
To initialize a byte array in Java, you can use the array initializer syntax, like this:
- How do I parse command line arguments in Java?Java
To parse command line arguments in Java, you can use the main() method of your application's entry point class.
- How do I print the full NumPy array, without truncation?Python
To print the full NumPy array without truncation, you can use the numpy.set_printoptions() function and set the threshold parameter to np.inf.
- How do I sort a dictionary by value?Python
You can use the sorted() function and pass it the dictionary, along with the key parameter set to a lambda function that returns the value from the dictionary.
- How do you remove an array element in a foreach loop?PHP
It is generally not recommended to remove array elements while iterating over the array using a foreach loop, because the loop will behave unexpectedly when elements are removed.
- How to Add Elements to an Empty Array in PHPPHP
In this tutorial, we display and describe the most flexible ways to add elements to an empty array. Follow the steps and you will manage that easily.
- How To Add New Elements To A JavaScript ArrayJavaScript
To add new elements you can use the following JavaScript functions: push() unshift(), concat() function or splice(). See examples.
- How to add new elements to an array in Java?Java
To add new elements to an array in Java, you have a few options: If you know the size of the array in advance and the array is not full, you can simply assign a new value to an unused element in the array.
- How to Append an Array to Another in PHPPHP
While working with PHP, developers wonder how to append one array to another. This snippet is dedicated to the exploration of functions that help to do it.
- How to Append an Item to an Array in JavaScriptJavaScript
On this page, you can learn the ways of appending an item or multiple items to an array in JavaScript.
- How to Check for the Existence of Nested JavaScript Object KeyJavaScript
In this tutorial, you will find several methods that are used to test the existence of the nested JavaScript object keys. Also, find how to avoid TypeError.
- How to Check if an Element is Present in an Array in JavaScript?JavaScript
Very often we need to check whether the element is in an array in JavaScript or not. In this snippet, we are going to learn some methods to do that.
- How to Convert a Comma-Separated String into ArrayJavaScript
Read this tutorial and learn information about the JavaScript built-in split() method which is called for converting a comma-separated string in an array.
- How to Convert Arguments Object to an ArrayJavaScript
Read this JavaScript tutorial and learn information about the useful methods that are used for converting array-like arguments object to an Array easily.
- How to Convert Set to Array in JavaScriptJavaScript
Read the tutorial and learn about several methods used for converting Set to Array in JavaScript. Also, read about differences between these two structures.
- How to Convert String to Title Case with JavaScriptJavaScript
Read this JavaScript tutorial and learn information about the combinations of methods that make it possible to convert the string to title case easily.
- How to Copy Array Items into Another ArrayJavaScript
Read this JavaScript tutorial and learn several useful methods of copying array items into another array. Get to know which method to choose for your case.
- How to Create a Two Dimensional Array in JavaScriptJavaScript
The two-dimensional array is an array of arrays. Read this JavaScript tutorial and find out several methods of creating two dimensional arrays easily.
- How to create a two-dimensional array in Java?Java
To create a two-dimensional array in Java, you can use the following syntax:
- How to Create an Array Containing 1…NJavaScript
Read this JavaScript tutorial and get information concerning the problem of creating an Array that contains 1 through to N. Find two methods for solving it.
- How to crop an image in OpenCV using PythonPython
You can use the cv2.imread() function to read an image into memory, and then use the cv2.rectangle() function to draw a rectangle around the region you want to crop.
- How to declare and add items to an array in Python?Python
To declare an array in Python, you can use the array module.
- How to Declare and Initialize an Array in JavaScriptJavaScript
Read this tutorial and learn the two basic methods of declaring and initializing an Array in JavaScript. Also, read about the differences of the methods.
- How to Delete an Element from an Array in PHPPHP
In this short tutorial, you will find the most proper solution to the commonly asked question by programmers: how to delete an element from an array.
- How to Empty an Array in JavaScriptJavaScript
This tutorial provides useful information about clearing an existing array in JavaScript. Get familiar to multiple methods and find the best one for you.
- How to Extend an Existing JavaScript Array with Another Array Without Creating a New ArrayJavaScript
Read this JavaScript tutorial and learn about several useful methods for extending an existing an Array with another array without creating a new array.
- How to find array / dictionary value using key?PHP
In PHP, you can use the $array[$key] syntax to get the value stored at a particular key in an array.
- How to find average from array in php?PHP
You can use the array_sum function to get the sum of all the values in an array, and then divide that sum by the number of elements in the array to get the average.
- How to Find the Min/Max Elements in an Array in JavaScriptJavaScript
Read this JavaScript tutorial and learn about the methods used to find the minimum and maximum number of elements in an array. Find the fastest solution.
- How to Find the Sum of an Array of NumbersJavaScript
Read this JavaScript tutorial and learn several methods used to find or calculate the sum of an array of numbers. Also, find which is the fastest one.
- How to get an array of specific "key" in multidimensional array without loopingPHP
You can use the array_column function to get an array of specific keys from a multidimensional array.
- How to get last key in an array?PHP
You can use the end() function to get the last element of an array in PHP.
- How to Get the Difference Between Two Arrays in JavaScriptJavaScript
Read this tutorial and learn several JavaScript and jQuery methods that help you get the difference between two arrays easily. Choose the best one for you.
- How to Get the First Element of an Array in PHPPHP
This snippet gives you an opportunity to learn how to get the first element of an array using PHP. You can choose among the provided functions.
- How to Get the Index of an Array that Contains Objects in JavaScriptJavaScript
Read this JavaScript tutorial and learn several useful, fast and simple methods that are used for getting the index of an array that contains objects.
- How to Get the Last Item in an ArrayJavaScript
Read the tutorial and learn the methods of getting the last item in the array. Get to know the methods and their peculiarities to find the best solution.
- How to Get URL ParametersJavaScript
Read this JavaScript tutorial and learn how you can easily get the URL parameters with the help of the methods provided by the URLSearchParams interface.
- How to handle Undefined Offset in laravel?PHP
In Laravel, an "Undefined offset" error typically occurs when trying to access an array index that does not exist.
- How to initialize a two-dimensional array in Python?Python
You can use the built-in list function to create a 2D array (also known as a list of lists) in Python.
- How to Insert an Item into an Array at a Specific IndexJavaScript
Read this JavaScript tutorial and learn the right method of inserting an item into an array at a specific index. Try examples and copy the code right away.
- How to Loop through an Array in JavaScriptJavaScript
The most common ways to loop through an array in JavaScript are the for, for/in and while loops. See how to use them. Examples.
- How to Loop Through Array and Remove Items Without Breaking the For LoopJavaScript
Read this JavaScript tutorial and learn some useful information about the method of looping through an Array and removing items without breaking for loop.
- How to Move an Array Element from One Array Position to AnotherJavaScript
In this JavaScript tutorial, you will read and learn information about an easy insert strategy method of moving the array element to another position.
- How to Randomize (shuffle) a JavaScript ArrayJavaScript
In JavaScript, there no any built-in method of shuffling a JavaScript array. Read this tutorial and learn what is the popular method of randomizing arrays.
- How to Remove an Element from an Array in JavaScriptJavaScript
Read this tutorial and learn what several useful Array methods exist that will help you remove the specified element from an Array in JavaScript easily.
- How to Remove and Reindex an Array Element in PHPPHP
Sometimes, in the course of working with PHP, it is necessary to remove and reindex an array element. Here, you will find simple and helpful methods to do that.
- How to remove duplicate values from a multi-dimensional array in PHPPHP
To remove duplicate values from a multi-dimensional array in PHP, you can use the following approach:
- How to Remove Empty Array Elements in PHPPHP
Very often, it is necessary to remove empty elements of the array in PHP. This snippet will provide you with the most common and efficient way to do it.
- How to Remove Empty Elements from an Array in JavascriptJavaScript
Read this tutorial and learn the method of removing empty elements from an Array. Also, read about removing falsy elements that include an empty string.
- How to rename sub-array keys in PHP?PHP
You can use the array_combine function in PHP to create a new array by using one array for the keys and another for the values.
- How to Replace a Character at a Particular Index in JavaScriptJavaScript
In this tutorial, you will read and learn detailed information about methods that are used to replace a character at a particular index in JavaScript.
- How to Separate Odd and Even Elements from an Array Without Using a Loop in PHPPHP
Here, we provide a snippet, explaining how to separate odd and even elements from an array without using a loop in PHP. Read on and check out the examples.
- How to Sort a Multidimensional Array by ValuePHP
In this short tutorial, you will learn the most efficient ways to easily sort a multidimensional array by value using PHP. Just follow the steps below.
- How to Sort an Array of IntegersJavaScript
Read this JavaScript tutorial and learn useful information about the logic of the sort() method which will help you sort an array of integers correctly.
- How to Sort Array Alphabetically in JavaScriptJavaScript
Read this JavaScript tutorial and learn the two methods of sorting the elements of an array in alphabetical order based on the values of the elements.
- How to Split a String Breaking at a Particular Character in JavaScriptJavaScript
Read this tutorial and find two easy and fast methods of splitting the string breaking at a particular character in JavaScript. Also, find and try examples.
- How to Split Array into ChunksJavaScript
Read the tutorial and find several easy and fast approaches to splitting a JavaScript array into smaller chunks. Choose one of the methods and try examples.
- How to use angularjs filtersAngularJs
Learn How to use Angularjs filters. AngularJs lets us create custom filters and use it like you use other filters. Try examples yourself and see the result.
- How to validate array in Laravel?PHP
In Laravel, you can use the validate method on the Validator facade to validate an array of form data.
- How to Write a Function that Accepts Any Number of Arguments in JavaScriptJavaScript
Read this JavaScript tutorial and find two easy methods of writing a function that will accept an indefinite number of arguments. See and try examples.
- HTML/PHP - Form - Input as arrayPHP
To create an HTML form that submits an array as a form parameter, you can use the name attribute of the input element and give it a value in the form of an array.
- Java Array Sort descending?Java
To sort an array in descending order in Java, you can use the Arrays.sort method and pass it a comparator that compares the elements in reverse order.
- Java dynamic array sizes?Java
In Java, you can implement a dynamic array (i.e., an array that can grow and shrink as needed) by using an ArrayList or an ArrayDeque.
- Limit array to 5 itemsPHP
You can use the "array_slice" function in PHP to limit an array to a specific number of items.
- List of All Locales and Their Short Codes?PHP
Here is a list of all the locales and their corresponding short codes that are available in PHP.
- Make copy of an arrayJava
To make a copy of an array in Java, you can use the clone() method of the Object class. The clone() method creates a shallow copy of the array, which means that it creates a new array with the same elements as the original array
- Message: Trying to access array offset on value of type nullPHP
This error message is indicating that you are trying to access an array offset (i.e., an element of an array) but the value being accessed is null.
- Most efficient way to map function over numpy arrayPython
There are several ways to apply a function to every element of a numpy array, and the most efficient method will depend on the size and shape of the array, as well as the complexity of the function.
- PHP - Extracting a property from an array of objectsPHP
To extract a property from an array of objects in PHP, you can use the array_column function.
- PHP append one array to another (not array_push or +)PHP
To append one array to another in PHP, you can use the array_merge function.
- PHP How to add to end of array?PHP
In PHP, you can add an element to the end of an array using the array_push() function.
- PHP: Limit foreach() statement?PHP
To limit the number of iterations in a foreach loop in PHP, you can use a simple counter variable and a break statement.
- Print array to a filePHP
To print an array to a file in PHP, you can use the file_put_contents() function, which writes a string to a file.
- Remove all elements from array that do not start with a certain stringPHP
You can use the array_filter() function in PHP to remove all elements from an array that do not start with a certain string.
- Removing an element from an Array in JavaJava
There are a few different ways you can remove an element from an array in Java. Here are a few options:
- Reverse order of foreach list itemsPHP
To reverse the order of the items in a list when using a foreach loop in PHP, you can simply reverse the array using the array_reverse function before the loop.
- search a php array for partial string matchPHP
You can use the array_filter() function in PHP to search through an array and return only the elements that contain a certain string.
- search and replace value in PHP arrayPHP
In PHP, you can use the array_map() function to search and replace values in an array.
- selecting unique values from a columnPHP
To select unique values from a column in PHP, you can use the array_unique function.
- Submit html table data with via form (post)PHP
Here is an example of how to submit an HTML table data via a form (using the POST method) using PHP:
- Type hinting in PHP 7 - array of objectsPHP
In PHP 7, type hinting can be used to specify the expected data type of a function or method parameter.
- Way to get all alphabetic chars in an array in PHP?PHP
You can use the range() function to get all alphabetic characters in an array in PHP.
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?Java
java.lang.ArrayIndexOutOfBoundsException is an exception that is thrown when you try to access an element of an array with an index that is out of bounds. This can happen if you try to access an index that is either negative or greater than or equal to
- What is "String args[]"? parameter in main method JavaJava
String args[] is a parameter in the main method of a Java program. It is an array of strings that can be used to pass command-line arguments to the program when it is executed.
- Which is a better way to check if an array has more than one element?PHP
There are several ways to check if an array has more than one element in PHP.
- Why is processing a sorted array faster than processing an unsorted array in Java?Java
Processing a sorted array can be faster than processing an unsorted array because certain algorithms and operations have a lower average time complexity when the input is already sorted.