This question already has an answer here:
Array (
[0] => Array (
[0] => uploads/AP02A66_31_upload1_1357736699_SeamTrade.php
)
[1] => Array (
[0] => uploads/AP02A66_31_upload1_1357736699_SiteController.php
)
)
How to convert the above array into one indexed array so that it will come in the form like,
Array (
[0] => uploads/AP02A66_31_upload1_1357736699_SeamTrade.php
[1] => uploads/AP02A66_31_upload1_1357736699_SiteController.php
)
</div>
Function to flatten a nested array:
function flatten_array(array $array) {
return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array)),false);
}
for($i=0;$i<count($yourArray);$i++)
{
$yourArray[$i] = $yourArray[$i][0];
}
$sourceArray = array(
array('uploads/AP02A66_31_upload1_1357736699_SeamTrade.php'),
array('uploads/AP02A66_31_upload1_1357736699_SiteController.php'),
);
$newArray = array_map(function ($nestedArray) {
return $nestedArray[0];
}, $sourceArray);
or another way (that one will do that in place, so beware that source array will be changed):
foreach ($sourceArray as &$element) {
$element = $element[0];
}
or more flexible way - if your nested arrays can contain more than one element:
$newArray = array();
foreach ($sourceArray as $nestedArray) {
$newArray = array_merge($newArray, $nestedArray);
}
and there is many other ways, but I suppose those above should be enough ;)
Another possible solution, assuming your array is called $input
:
$output = array();
array_walk_recursive($input, function($element) use (&$output){
$output[] = $element;
});