Your input data (enriched with other data-types, -for testing-) and assuming you are using recent PHP versions:
$input = array(
0=>
array(
"ID"=> "2"
),
1=>
array(
"ID"=> "3"
),
"iamnotanarray", 100, null
);
exemplary:
$out = array_map( function($el){ return @current($el);}, $input);
generally:
$out = array_combine(
array_keys($ret)
,array_map( function($el){ return @current($el);}, $ret)
)
output:
var_export($out);
array (
0 => '2',
1 => '3',
2 => NULL,
3 => NULL,
4 => NULL,
)
var_dump($out);
array(5) {
[0]=>
string(1) "2"
[1]=>
string(1) "3"
[2]=>
NULL
[3]=>
NULL
[4]=>
NULL
}
To filter potentially unwanted data types, you may use:
$out = array_filter($out, is_string);
var_dump($out);
array(2) {
[0]=>
string(1) "2"
[1]=>
string(1) "3"
}
I didn't time it (yet), but this is using PHP's native precompiled functions. Speed varies with the gcc compiler optimizations of your PHP executable.
Note: @current
is dirty, not recommended and just used for brevity/readability. It would yield the same effect as is_array($el) ? current($el) : NULL;