PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Oct 19, 2017 3:56 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Apr 26, 2017 3:17 pm 
Offline
Forum Commoner

Joined: Fri Aug 14, 2009 9:43 am
Posts: 66
Hi Everyone,
I've been looking online for a way to reset the keys of sub arrays. Heres a portion of what I have:

Syntax: [ Download ] [ Hide ]
Array
(
    [userfile] => Array
        (
            [name] => Array
                (
                    [5] => IMG_20170325_152954871_HDR.jpg
                )

            [type] => Array
                (
                    [5] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [5] => /Applications/XAMPP/xamppfiles/temp/phpA49huQ
                )

        )

)


I've found a couple of examples that are close to what I'm looking for:

Syntax: [ Download ] [ Hide ]
$_FILES = array_map('array_values', $_FILES);

        // And also tried...

foreach ($_FILES as &$val) {
            $val = array_values($val);
 


But both of them produce this output:

Syntax: [ Download ] [ Hide ]
Array
(
    [userfile] => Array
        (
            [0] => Array
                (
                    [5] => IMG_20170325_152954871_HDR.jpg
                )

            [1] => Array
                (
                    [5] => image/jpeg
                )

            [2] => Array
                (
                    [5] => /Applications/XAMPP/xamppfiles/temp/phpA49huQ
                )
         )
    )


I want to go one level deeper and reset the sub array keys like so:

Syntax: [ Download ] [ Hide ]
Array
(
    [userfile] => Array
        (
            [name] => Array
                (
                    [0] => IMG_20170325_152954871_HDR.jpg
                )

            [type] => Array
                (
                    [0] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [0] => /Applications/XAMPP/xamppfiles/temp/phpA49huQ
                )
         )
    )


Everything I've tried has failed. Any ideas? Thanks so much.
Cheers,
Rick


Top
 Profile  
 
PostPosted: Mon May 01, 2017 12:03 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13434
Location: New York, NY, US
Maybe something like:
Syntax: [ Download ] [ Hide ]
$myfiles = [];
foreach ($_FILES as $file => $filedata) {
    foreach ($filedata as $key => $value) {
        $myfiles[$file][$key][0] = $filedata[$key][5];
    }
}

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group