Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Cara mengubah posisi MYSQL db di PHP

Coba fungsi ini:

function array_transpose($array, $selectKey = false) {
    if (!is_array($array)) return false;
    $return = array();
    foreach($array as $key => $value) {
        if (!is_array($value)) return $array;
        if ($selectKey) {
            if (isset($value[$selectKey])) $return[] = $value[$selectKey];
        } else {
            foreach ($value as $key2 => $value2) {
                $return[$key2][$key] = $value2;
            }
        }
    }
    return $return;
}


$fruits = array(
    array('id' => 1, 'name' => 'Apple', 'color' => 'Red'),
    array('id' => 2, 'name' => 'Orange', 'color' => 'Orange'),
    array('id' => 3, 'name' => 'Mango', 'color' => 'Yellow')
);
echo "<pre>";
print_r(array_transpose($fruits));
echo "</pre>";
";

Pengembalian:

Array
(
    [id] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [name] => Array
        (
            [0] => Apple
            [1] => Orange
            [2] => Mango
        )

    [color] => Array
        (
            [0] => Red
            [1] => Orange
            [2] => Yellow
        )

)



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Jangan izinkan kunci utama komposit terbalik di MySQL

  2. MySQL:Tampilan vs Prosedur Tersimpan

  3. Cara Mengurangi Hari di MySQL

  4. MySQL Beberapa Kiri Bergabung

  5. Berapakah nomor ID terbesar yang dapat dihasilkan oleh peningkatan otomatis di mysql