多くの可能なアプローチ。それらのいくつかのために、この単純な例を見てみましょう:
<?php
$input = [
[
'accountname' => 'test',
0 => 'test'
],
[
'accountname' => 'test2',
0 => 'test2'
]
];
// #1: treating the input as a table and selecting a "column":
var_dump(array_column($input, 0));
// #2: using an anonymous "lambda" function:
$output = [];
array_walk($input, function($val) use (&$output) { $output[]=$val[0]; });
var_dump($output);
// #3: destructive approach flattening the input:
$output = $input;
array_walk($output, function(&$val) { $val = $val[0]; });
var_dump($output);
// #4: simple "foreach" loop, traditional approach:
$output = [];
foreach($input as $entry) {
$output[] = $entry[0];
}
var_dump($output);
// #5: classical "for" loop, scales better for big data:
$output = [];
for($i=0; $i<count($input); $i++) {
$output[] = $input[$i][0];
}
var_dump($output);
それぞれの出力は明らかである:
array(2) {
[0] =>
string(4) "test"
[1] =>
string(5) "test2"
}
あなたは、あなたの質問に、あなたの現在のコードを追加するのを忘れ。 – arkascha