Questions tagged [array-column]

The array_column() return the values from a single column in the input array.

$records = array(
    array(
        'id' => 2135,
        'first_name' => 'John',
        'last_name' => 'Doe',
    ),
    array(
        'id' => 3245,
        'first_name' => 'Sally',
        'last_name' => 'Smith',
    )
);
$first_names = array_column($records, 'first_name');
print_r($first_names);

The above example will output:

Array
(
    [0] => John
    [1] => Sally
)
102 questions
1
vote
4 answers

How to Sum Columns of a Multi-Dimensional Array?

I have array data like : [ 'A1' => [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'A2' => [1, 1, 0, 0, 0, 0, 0, 0, 0, 0], 'A3' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]; I want to add the column values and produce a flat array of sums. I want answer like…
jaya
  • 327
  • 3
  • 4
  • 16
1
vote
4 answers

Parse lines of a text file where values are separated by a varying number of whitespace characters

I need to get the company name and its ticker symbol in different arrays. Here is my data which is stored in a txt file: 3M Company MMM 99 Cents Only Stores NDN AO Smith Corporation AOS Aaron's, Inc. AAN and so on How would I do this…
user126284
0
votes
1 answer

How to remove duplicate values by comparing two array type column values in Postgresql?

I want to remove duplicate values by comparing two array type column values. I want to get the result of subtracting the fruit I already ate from my favorite fruit. But if there ara 2 apples in your favorite fruit column and 1 apple in eaten fruit…
krchoi
  • 1
0
votes
0 answers

Replace null values to 0 in Bigquery

I have null and scientific values(e) on array column in my table data. My data is in following format: . I do need to replace all these values to 0.
0
votes
1 answer

json_decode array returns with missing array indexes

I am trying to build a web-gui for jaredhendrickson13/pfsense-api (https://github.com/jaredhendrickson13/pfsense-api) Either I can't get array indexes on return or they not there. I am using laravel8 with php 7.4 My code to get responses; $curl =…
zehyr
  • 41
  • 5
0
votes
1 answer

How to remove duplicates value of same key of multidimensional array in PHP

I have a multidimensional array and need to remove entries with the same values for a key. eg. Array ( [0] => stdClass Object ( [id] => 1177930857 [lat] => 24.479280471802 [lon] => 46.973030090332 [status] =>…
geeth
  • 704
  • 2
  • 14
  • 42
0
votes
1 answer

Use column values from one subarray as keys for anotheer subarray's values

I have an object as below, {"metaData":[{"name":"a"},{"name":"b"}],"rows":[[1,2],[3,4],[5,6]]} I would like to change it to [["a"=>1,"b"=>2],["a"=>4,"b"=>5],["a"=>5,"b"=>6]] Is there any faster one liner that can convert this without going thru a…
Wahsei
  • 289
  • 2
  • 6
  • 16
0
votes
1 answer

Extract elements from Spark array column using SparklyR "select"

I have a Spark dataframe in a SparklyR interface, and I'm trying to extract elements from an array column. df <- copy_to(sc, data.frame(A=c(1,2),B=c(3,4))) ## BUILD DATAFRAME dfnew <- df %>% mutate(C=Array(A,B)) %>% select(C) ##…
Jeff
  • 60
  • 5
0
votes
1 answer

How To Search In Multiple Columns In Json File Array?

I have a json file with this content : [ { "id": "apple", "symbol": "app", "name": "Apple", }, ] I Want To Search In This Json File In id Or symbol Or name Columns, I Write This Code : $nameOrIDOrSymbol="apple"; // user…
Amin Arjmand
  • 435
  • 7
  • 21
0
votes
1 answer

Format number in array within an array_sum

I have a view in a laravel project where I have to print the sum of some array columns. I Have this kind of code to achieve the result: @foreach($data as $row) ....... @foreach($row as $key => $value) @if(in_array($key, ['PARZ. IN', 'PARZ.…
DannyV
  • 9
  • 3
0
votes
2 answers

How can I sort IDs by multiple attributes

I have a multi-dimensional array of fencer ids with 3 attributes (see code below) Array ( [0] => Array ( [id] => 5255 [ratio] => 1 [point_difference] => -25 [given] => 0 ) [1]…
0
votes
2 answers

PHP array_column to return with values only

Is it possible to get a result from array_column that has values only? sample array i want to array_column $array = [ ['name' => ''], ['name' => 'John'], ['name' => 'Doe'] ] when i use array_column this is what i get Array ( [0] => …
royudev
  • 53
  • 6
0
votes
2 answers

Use array_column in combination with preg_match

Lets suppose we have an array of arrays that needs to be converted to rows From this: Array ( [subject] => Array ( [0] => EDN:LOC:DERR [1] => EDN:LOC:DOXX [2] => EDN:LOC:NTTT [3] =>…
0
votes
2 answers

How do I get index of repeated data from multi dimension array in different variables using array_search() method

how to get index of repeated data from a multi dimension array using array_search() or array_column() method function Search($value, $array) { return(array_search($value, $array,false)); } $array = array(45, 5, 1, 22, 22, 10, 10); $value = "10";…
0
votes
3 answers

How can I check and delete duplicate arrays?

how can I check and delete duplicate arrays? Example: $a = array( array( 'id' => 1, 'name' => 'test' ), // Next array is equal to first, then delete array( 'id' => 1, 'name' => 'test' ), // Different array,…