Skip to content

Instantly share code, notes, and snippets.

@wasipo
Created May 29, 2020 05:39
Show Gist options
  • Save wasipo/0b4a4ec54a7a6c83b4f51c58db799ced to your computer and use it in GitHub Desktop.
Save wasipo/0b4a4ec54a7a6c83b4f51c58db799ced to your computer and use it in GitHub Desktop.
1行に項目の配列が入ってるから項目の配列を行にして、各行に項目の値を入れたい
public function testRowArrayConvert() {
$ar = [
'a' => ['123','123','123','123'],
'b' => ['123','123','123','123'],
'c' => ['123','','123','123'],
'd' => ['123','123',null,'123'],
'e' => ['123','123','','123'],
'f' => ['','123','123','123'],
];
$arC = count($ar['a']);
$arR = [];
for($i = 0; $i < $arC; $i++) {
foreach($ar as $key => $array) {
$arR[$i][$key] = $array[$i];
}
}
self::assertTrue(is_array($arR));
self::assertTrue(count($arR) === $arC);
$keyyyyyyyyyyyy = array_keys($ar);
foreach($keyyyyyyyyyyyy as $key) {
for($i = 0; $i < count($arR); $i++) {
self::assertTrue(array_key_exists($key, $arR[$i]));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment