Reputation: 43
Array
(
[0] => Array
(
[A] => Demo 1
[B] => Demo 2
[C] => Demo 3
[D] => Demo 4
)
[1] => Array
(
[A] => Sample 1
[B] => Sample 2
[C] => Sample 3
[D] => Sample 4
)
)
Find the column key like as (A,B,C,D)
Upvotes: 0
Views: 66
Reputation: 1459
It's possible to do it by merging by array_merge and then extract the keys by array_keys
$res = array();
foreach($array as $sub) {
$res = array_merge($res, $sub);
}
$keys = array_keys($res);
print_r($keys);
This will output:
Array
(
[0] => A
[1] => B
[2] => C
[3] => D
)
Upvotes: 2
Reputation: 6498
You can use foreach like this:
foreach ($stdTable as $row) {
echo "'".implode("','", array_keys($row))."'<br>".PHP_EOL;
}
OR
foreach ($stdTable as $row) {
$keys='';
foreach($row as $key => $value){
$keys.= $key.',';
}
echo rtrim($keys,',');
}
Upvotes: 0