Untitled Diff

Created Diff never expires
19 刪除
總計
刪除
單詞
總計
刪除
要繼續使用此功能,請升級到
Diffchecker logo
Diffchecker Pro
23
21 新增
總計
新增
單詞
總計
新增
要繼續使用此功能,請升級到
Diffchecker logo
Diffchecker Pro
21
<?php
<?php
// Turn an array into a key=>value pair. Assumes the key is the first item in the sub-array.
// Turn an array into a key=>value or key=>array pair.
public function column_into_keys(array $array): array {
// Assumes the key is the first item in the sub-array.

public function columnIntoKeys(array $array): array {
// get the name of the column that contains the record id
$key = key($array[0]);
// skip empty arrays

if (! count($array)) return [];
// loop through each result row
foreach($array as $row) {
foreach($array as $row) {

// pop the new key off the top of the array
// pop the value of the row identifier off the top of the array
$id = array_shift($row);
$id = array_shift($row); // O(n)

// is there only one item left in the array?
// if there is only one item left in the array...
if (count($row) == 1)
$result[$id] = (count($row) == 1)
// get the first value
? current($row) // ...get the first value
$result[$id] = current($row);
: $row; // ...get the rest of the array
else
// get all of the values
$result[$id] = $row;
}
}

return $result;
return $result;
}
}