Genta Haetami Putra
Genta Haetami Putra

Reputation: 113

Call the values in foreach an array

My Code is :

$result = array();
foreach ($inbox as $key => $p) {
   $group = $result[$p->suratmasuk_id][] = $p;
   foreach ($group as $key => $pp) {
     echo $pp.'<br>';
   }
}

When i var_dump($pp), the result is :

string(2) "25" string(1) "3" string(3) "492" string(2) "75" string(0) "" string(0) "" string(13) "Belum Selesai"

string(2) "26" string(1) "4" string(3) "492" string(2) "75" string(0) "" string(0) "" string(13) "Belum Selesai" 

I just want echo "25" and "26"

How is it? Please help me. Thank you

Upvotes: 0

Views: 46

Answers (1)

Girish
Girish

Reputation: 12117

just use php array manipulation function, it's easy and short, when your have 2d array

$a = [[25, 22,11], [26, 44, 33]];
print_r(array_column($a, 0));

And when you have key then you can use key instead of array index (0)

Upvotes: 1

Related Questions