3
am ultilizando PDO
for mysql query,and I would like to grab the keys of an array, tried several methods and failed, e.g.:$arr_cars['id']
an error has 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)
What are you trying to do? Why are you trying to create an identical array from another?
– Rodrigo Rigotti
@Rodrigo Rigotti I made a select in the database that has 4 records and print the result
– David