Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Get values of same key from multiple array in php

I'm trying to separate the "TID" in an array from these multiple arrays but I couldn't find the efficient solution.

I've the following type of arrays in one variable:

Array
(
    [0] => Array
        (
            [tid] => 168
        )

)
Array
(
    [0] => Array
        (
            [target_id] => 14
        )

    [1] => Array
        (
            [target_id] => 15
        )

    [2] => Array
        (
            [target_id] => 37
        )

)
Array
(
)
Array
(
    [0] => Array
        (
            [target_id] => 36
        )

)
Array
(
    [0] => Array
        (
            [target_id] => 14
        )

    [1] => Array
        (
            [target_id] => 15
        )

)
Array
(
    [0] => Array
        (
            [target_id] => 36
        )

)
Array
(
    [0] => Array
        (
            [tid] => 168
        )

    [1] => Array
        (
            [tid] => 167
        )

)

These values are in one variable and there can be unlimited arrays.

And Expected Output:

Array
(
    [0] => Array
        (
            [tid] => 168
        )
    [1] => Array
        (
            [tid] => 168
        )

    [2] => Array
        (
            [tid] => 167
        )

)
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You are searching for array_column.

Here is the syntax

array array_column ( array $input , mixed $column_key [, mixed $index_key = null ] )

Description

array_column — Return the values from a single column in the input array

Example :

$records = array(
    array(
       tid => 167
    ),
    array(
        'id' => 3245,
        'first_name' => 'Sally',
         tid => 166
    ),
    array(
        'id' => 5342,
        'first_name' => 'Jane',
         tid => 168
    ),
    array(
        'id' => 5623,
        'first_name' => 'Peter',
         tid => 169
    )
);

$ids= array_column($records, 'tid');

OUTPUT :

Array
(
    [0] => 167
    [1] => 166
    [2] => 168
    [3] => 169
)

If you have more arrays,

$records1 = [ ['tid' => 169]];
$ids1 = array_column($records1, 'tid');

then you can do array_merge.

$ids = array_merge($ids, $ids1);

OUTPUT :

Array
(
    [0] => 167
    [1] => 166
    [2] => 168
    [3] => 169
    [4] => 169
)
about 4 years ago · Santiago Trujillo Relatório

0

$arr1= array("1"); // first 
$arr2 = array("2") // second array
$new = array();

foreach($arr1 as $key=>$value){
 if($key=="yourkey"){
   $new[]=$value;
 }
}

foreach($arr2 as $ke2=>$valu2){
   if($key2=="yourkey"){
     $new[]=$value2;
   }
 }

 print_r($new);
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda