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
0
votes
2 answers

How to reassign indexes with associative keys using a column value?

I need help to replace some specific subarray indexes with associative keys in my multidimensional array. My data is coming from an xml file from another system. For my next process (Import in another System), I need these associative keys. Here is…
0
votes
2 answers

Get count of each unique word across all strings in an array column

I'd like to get a unique word count including all strings in an array column. Input: [ [ "Query" => "hehe haha hihi", "Merry" => "1.11" ], [ "Query" => "hehe hoho hrooo", "Merry" => "1.12" ] ] I…
hrca
  • 3
  • 2
0
votes
3 answers

Filter array based on the exploded key value

I have an associated array, $array2 = array( array('customer_id' => '01', 'categories' => '',), array('customer_id' => '02', 'categories' => '',), array('customer_id' => '03', 'categories' => '20,26,18',), array('customer_id'…
hakkim
  • 666
  • 15
  • 36
0
votes
1 answer

Unexpected results php foreach loop with array_column

thanks in advance for any help! I´m an absolute newbie to php but trying to get along. I have an array $result which contains something like: Array ( [0] => Array ( [id] => xyz [from] => Array ( …
user8801897
0
votes
6 answers

Group 2d array in batches of 10 rows then sum the values in each batch

I have an array of rows which need to be batched into groups of ten rows then their values summed. Sample array with 13 rows: [ ['amount_paid' => 2050.00], ['amount_paid' => 2050.00], ['amount_paid' => 2050.00], ['amount_paid' =>…
Martin
  • 365
  • 4
  • 7
  • 22
0
votes
2 answers

Retrieve key value based on another key value within the same row of a PHP array

I'm working with an indexed PHP array that resembles this structure: $result = Array( [0] => Array([storepickup_id] => 3[sku] => 691294[inventory] => 33[reserve] => ) [1] => Array([storepickup_id] => 3[sku] => 692284[inventory] => 3[reserve]…
sparecycle
  • 2,038
  • 5
  • 31
  • 58
0
votes
5 answers

Create a flat array of values from an array column containing array-type data

I have this array in PHP. $all = array( array( 'titulo' => 'Nome 1', 'itens' => array( 'item1', 'item2', 'item3') ), array( 'titulo' => 'Nome 2', 'itens' => array( 'item4', 'item5', 'item6') ), array( 'titulo' => 'Nome 4', …
0
votes
6 answers

How to convert array values to comma seperated string based on specified given array values..?

I have the array as specified below Array ( [5] => Array ( [id] => 5 [first_name] => Diyaa [profile_pic] => profile/user5.png ) [8] => Array ( [id] => 8 [first_name] => Raj [profile_pic] => profile/user8.png ) …
ArunValaven
  • 1,753
  • 2
  • 25
  • 44
0
votes
1 answer

PHP 7 array columns not working for multidimensional array

Below is my array structure: Array ( [2016-09-01] => Array ( [1] => Array ( [hours_type_id] => 1 [date] => 2016-09-01 [hours] => 8.00 …
Wolverine
  • 455
  • 3
  • 8
  • 26
0
votes
1 answer

How to replace arrays of multidimensional array with items of that array using php?

In the multi-dimensional array below how would I replace the top level indices [0] [1] & [2] with their respective values from [SUB1] Array ( [0] => Array ( [SUB1] => AAA111 [SUB2] => Description 1 …
0
votes
1 answer

How to combine two arrays by deep key?

I want to combine two arrays using specified deep subarray values. I have two different arrays with different structures and I want to combine them so that if the "primary keys" match then add second array's values to the first array, if not then…
SAHAR
  • 49
  • 1
  • 8
0
votes
2 answers

How to combine each subarray of subarrays and store them as comma separated strings?

I need to join all subarray Name values in single subarray. Given input format: Array ( [0] => Array ( [0] => Array ( [Name] => kumar ) [1] => Array …
0
votes
2 answers

How to sum the 2nd level values of a 2-dim array based on the 2nd level keys?

I have a multi-dimensional array like this: array( 0 => array( 11 => 18.000, 14 => 25.100, 15 => 5.000, 16 => 8.000, 19 => 21.600' ), 1 => array( 11 => 9.100, 12 =>…
Wasswa Samuel
  • 2,139
  • 3
  • 30
  • 54
0
votes
3 answers

Get single column of data from mysql_query result

I am currently using a mysql_query with the UNION function. This is the array that I get: Array ( [0] => bob [added] => bob ) Array ( [0] => test1 [added] => test1 ) Is there a way that I can take this array, merge it, remove the…
user2898075
  • 79
  • 1
  • 3
  • 10
0
votes
3 answers

Generate array of unique values in specific array column

I'm getting the desired results back from my query and now I'm having trouble figuring out how to manipulate the data into something usable. The ultimate goal is a json output to be used by google charts and I can do this on any one single…
ppetree
  • 826
  • 3
  • 15
  • 31