Created
May 29, 2020 05:40
-
-
Save wasipo/935064b250c0c991a2fb57700f3b25f7 to your computer and use it in GitHub Desktop.
1行に入力項目が配列として入っているので、入力項目の配列を行にして、行に対して各項目の値を入れたい。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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