1

Maybe I missed something, but really, I can't find a solution for this.

I want to change the format of the array I get from a glob function.

This is how my code looks now.

$my_files = glob('*.php');

and the result is an array:

array(
    '0' => 'about.php',
    '1' => 'admin-ajax.php',
    '2' => 'admin-footer.php',
    '3' => 'admin-functions.php',
    '4' => 'admin-header.php',
    '5' => 'admin-post.php',
    '6' => 'admin.php',
)

Now this is what exactly I want to have(to change the numbers with the text for each array, respectively):

array(
    'about.php'         => 'about.php',
    'admin-ajax.php'    => 'admin-ajax.php',
    'admin-footer.php'  => 'admin-footer.php',
    'admin-functions.php' => 'admin-functions.php',
    'admin-header.php'  => 'admin-header.php',
    'admin-post.php'    => 'admin-post.php',
    'admin.php'         => 'admin.php',
)

I need this as an array to include it using a variable in this way:

array(
    'name'      => 'Intern download file name',
    'id'        => $prefix .'blog_post_intern_url',
    'type'      => 'select',
    'options'   => $my_files,
),
3
  • I still don't understand why it has to be in that format. Commented Jan 22, 2013 at 16:28
  • 1
    @Jack That looks a bit like wordpress. I assume we do not want to know why this format is required ;) Commented Jan 22, 2013 at 16:30
  • @Jack, I have html select where are listed all my files from a folder(.zip files uploaded via FTP). And on front-end I have a download button where in the link is this file wich I selected. That's why I need the value to be the name of selected file. And yes, this is a wordpress metabox field. Commented Jan 22, 2013 at 16:43

2 Answers 2

6
$arrayWithKeysEqualValues = array_combine($my_files, $my_files);
Sign up to request clarification or add additional context in comments.

Comments

2

Try array_combine

$newArray = array_combine($originalArray, $originalArray);

1 Comment

The same answer like @fab . Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.