I am using PDO
for mysql query, and I would like to get the keys from an array, tried several methods and did not succeed, ex: $arr_cars['id']
an error occurred
class Cars extends DB{
static function getCars(){
$select = self::getConn()->prepare('SELECT id,image,carro FROM 'cars'');
$d = $select->fetchAll(PDO::FETCH_ASSOC);
return $d;
}
}
//classe
$data = Cars::getCars();
$arr_cars = array();
foreach($data as $key){
$arr_cars[] = $key;
}
var_dump($cars);
/*irá imprimir:
array (size=4)
0 =>
array (size=3)
'id' => string '1' (length=1)
'image' => string '1.jpg' (length=5)
'carro' => string 'bmw' (length=12)
1 =>
array (size=3)
'id' => string '2' (length=1)
'image' => string '2.jpg' (length=5)
'carro' => string 'mercedes' (length=17)
2 =>
array (size=3)
'id' => string '3' (length=1)
'image' => string '3.jpg' (length=5)
'carro' => string 'bentley' (length=9)
3 =>
array (size=3)
'id' => string '4' (length=1)
'image' => string '3.jpg' (length=5)
'carro' => string 'volvo' (length=12)