mysql - convert PDO resultset array to accessible Array PHP -
i using pdo statement below
$sql1 = "select food_typename foodtypes 1"; $statement1 = $pdo->prepare($sql1); $statement1->execute(); $results1 = $statement1->fetchall(pdo::fetch_assoc); print_r($results1); i getting output below:
array ( [0] => array ( [food_typename] => panjabi ) [1] => array ( [food_typename] => indian ) ) i want like
array('punjabi','indian') any suggestions please?
if you're running php >= 5.5
$results = array_column($results1, 'food_typename'); if you're running before versions of php,
$results = array_map( $results1, function($value) { homecoming $value['food_typename']; } ); though don't understand why can't work original array in first place
php mysql arrays pdo
No comments:
Post a Comment