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
3
votes
1 answer

How to insert in postgres Array Column using python Psycopg2 and parameter binding?

Following is my table structure in postgresql: CREATE TYPE lang AS ENUM ('english','hindi','marathi'); CREATE TABLE assignment ( title varchar(100), ids lang[] ); I want to insert a record in assignment table using parameter binding in…
Branel Moro
  • 132
  • 2
  • 9
3
votes
5 answers

Access and join two columns in an array separately

I have below array, Array ( [1] => Array ( [0] => Array ( [location] => X33 [usernumber] => 1 [order] => XX [part_number] => Hi ) …
rjcode
  • 1,193
  • 1
  • 25
  • 56
3
votes
3 answers

Generate an associative array from an array of rows using one column as keys and another column as values

I have a MySQL result set with 2 values in each row. Each time I loop through these results, I want to add them to an array. I want one value to be the key, and the other to be the array value. I tried this, but it doesn't seem to work: $dataarray[]…
mrpatg
  • 10,001
  • 42
  • 110
  • 169
2
votes
1 answer

I am with problems to do a query with array column in PostgreSQL with Spring Data

Entity I have it entity with a property that is text[]: @Entity(name = "entityname") @Table(name = "tablename") @ToString @TypeDefs({ @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class), @TypeDef(name = "list-array", typeClass =…
2
votes
2 answers

Find value from multidimensional array from given two values

I have the following array. Array ( [0] => Array ( [product] => p1 [item] => q1 [date] => d1 [status] => N ) [1] => Array ( [product] => p2 …
2
votes
1 answer

How to sum up a column of an input file given to a CombiTimeTable in Modelica

I have used a .txt file (T_in1) as an input in a 2D-CombiTimeTable in Modelica. It contains an array with the size of (4,2); the first column is time and the second one is the time-dependent variable. I would like to sum or (to get an average of)…
AJodeiri
  • 314
  • 2
  • 8
2
votes
2 answers

Implementing PHP array_column in Rust

I'm in the process of learning Rust, but I could not find an answer to this question. In PHP, there's the array_column method and it works this way: given an array of arrays (this would be a a Vector of vectors in Rust): $records = [ [1,2,3], …
Life after Guest
  • 299
  • 1
  • 11
2
votes
3 answers

What alternative of code that work in PHP7 in PHP5

I have a PHP code which runs on PHP7 but not in PHP 5, which PHP version in my server, that is my code: Array ( [0] => stdClass Object ( [userId] => 15 [name] => name0 [userName] => hh [centerName] => center10 …
Ali A. Jalil
  • 873
  • 11
  • 25
2
votes
3 answers

PHP sum array values by item.qty

I wonder if there is a faster way to sum i.e. the weight of each item by qty. $items = [ [ 'qty' => 1, 'weight' => 1, ], [ 'qty' => 2, 'weight' => 1, ], [ 'qty' => 3, …
cottton
  • 1,522
  • 14
  • 29
2
votes
3 answers

How can I find the value of and array by searching a value in a different array in the same key in PHP

My Array $json looks like this : Array ( [0] => Array ( [poulecode] => 495271 [teamcode] => 277986 [teamnaam] => JO19-1 (0225 Onder 19 competitie (najaar)) ) [1] => Array ( [poulecode] =>…
Mark
  • 23
  • 3
2
votes
2 answers

array_column not working for an array of objects?

This is my current array structure: array(2) { ["Ground"] => array(4) { [0] => object(Shipping\Model\Shipping)#337 (5) { ["shipping_id"] => NULL ["min_weight"] => string(4) "0.00" ["max_weight"] => string(4) "5.00" …
herondale
  • 729
  • 10
  • 27
2
votes
2 answers

Collect all values from nested array row of specific key

Need to create a list that consists of all values stored in the array row of a specific key (product_id). Currently, doing a print_r of my $bestsellers variable produces the following array: Array ( [0] => stdClass Object ( …
2
votes
2 answers

Store column data from a multidimensional array while preserving missing elements

I have an array ($myArray) which looks like Array ( [0] => Array ( [0] => Array ( [Date] => 1776-08-08 [Color] => Yellow [Description] => Rotten ) ) [1] => Array ( ) [2] => Array ([0]…
jumpman8947
  • 571
  • 1
  • 11
  • 34
2
votes
1 answer

Query against a Postgres array column type

TL;DR I'm wondering what the pros and cons are (or if they are even equivalent) between @> {as_champion, whatever} and using IN ('as_champion', 'whatever') is. Details below: I'm working with Rails and using Postgres' array column type, but having…
2
votes
1 answer

Generate unique ids for all column values in a multi-dimensional array

I have a file which looks like this: Papiers peints > 3D et Perspective > 3D Papiers peints > Carte du monde Papiers peints > Fleurs Papiers peints > Fleurs > Coquelicots Tableaux > Cartes du monde Tableaux > Fleurs Tableaux > Fleurs >…
flish
  • 596
  • 1
  • 6
  • 17