1
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 
)
cmbuckley
  • 36,905
  • 8
  • 73
  • 90
user1755949
  • 103
  • 1
  • 12
  • Just `foreach` given array and append it's elements to empty array – Artem L Jan 09 '13 at 13:14
  • 1
    Iterate over the array and create a new array like you want it... what exactly are you having troubles with? Also it's only respectful to format your code properly so that others have a chance to read it. – Felix Kling Jan 09 '13 at 13:15
  • 3
    You can check this one http://stackoverflow.com/questions/9481980/remove-first-levels-of-identifier-in-array It is the same question as yours – Nick Jan 09 '13 at 13:15

4 Answers4

5
for($i=0;$i<count($yourArray);$i++)
{
    $yourArray[$i] = $yourArray[$i][0];
}
x4rf41
  • 4,978
  • 1
  • 20
  • 31
2
$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 ;)

lupatus
  • 4,148
  • 16
  • 19
1

Another possible solution, assuming your array is called $input:

$output = array();
array_walk_recursive($input, function($element) use (&$output){
    $output[] = $element;
});
lethal-guitar
  • 4,289
  • 1
  • 17
  • 38
0

Function to flatten a nested array:

function flatten_array(array $array) {
    return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array)),false);
}
SDC
  • 13,914
  • 2
  • 32
  • 48