查詢資料庫後怎樣把數組的值取出來呢 只要索引值不要鍵名?

來源:互聯網
上載者:User
一開始這樣寫的
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
$sth=$pdo->query('select * from blog');
$result = $sth->fetchALL(PDO::FETCH_ASSOC);
foreach($result as $v){

print_r($v);

}
?>

後來人家告訴我這樣寫 可是這樣列印出來的還是和原來一樣 那應該怎麼改呢
$pdo=new PDO("mysql:host=localhost;dbname=mysql","root","");
$sth=$pdo->query('select * from user');
$result = $sth->fetchALL(PDO::FETCH_ASSOC);
$tmp_ary=array();
foreach($result as $v){

$tmp_ary[]=array_values($v);

}

echo '

';
print_r($tmp_ary);
echo '
';

回複內容:

一開始這樣寫的
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
$sth=$pdo->query('select * from blog');
$result = $sth->fetchALL(PDO::FETCH_ASSOC);
foreach($result as $v){

print_r($v);

}
?>

後來人家告訴我這樣寫 可是這樣列印出來的還是和原來一樣 那應該怎麼改呢
$pdo=new PDO("mysql:host=localhost;dbname=mysql","root","");
$sth=$pdo->query('select * from user');
$result = $sth->fetchALL(PDO::FETCH_ASSOC);
$tmp_ary=array();
foreach($result as $v){

$tmp_ary[]=array_values($v);

}

echo '

';
print_r($tmp_ary);
echo '
';

array_values瞭解PHP去除鍵的函數。

 "li", "sex" => 1        ),        array(            "user" => "er", "sex" => 2        )    );    var_dump($result);    $new = array();    foreach($result as $row){        $new[] = array_values($row);    }    var_dump($new);

在mysql取出資料的時候,貌似PDO 好像都帶了欄位的資訊,你用的時候注意下

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.