Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

How to convert below result into array? I want to make an array so I can assign to variable and use it

if($handle = opendir($path)){
    while(false != ($filename = readdir($handle))) {
        if($filename != "." && $filename != ".."){
            $name = preg_replace("/\\.[^.\\s]{3,4}$/", "", $filename);
            $name = str_replace('_', ' ', $name);
            $name = ucwords($name);
                echo $name;
        }           
    }
    closedir($handle);
}
share|improve this question

closed as off-topic by TMS, jeroen, andrewsi, nifr, George Brighton Mar 6 '14 at 12:54

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself." – nifr, George Brighton
  • "Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist" – TMS, jeroen, andrewsi
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
so what's your question? how to insert an item into an array? because then all the code you posted is just noise.. –  Karoly Horvath Jun 29 '13 at 18:41
    
Oh! new to php :( for instance in WP theme option where I have to use variable to assign select option value. since that's an array to crate field –  Code Lover Jun 29 '13 at 18:46

1 Answer 1

up vote 2 down vote accepted

Simply add the names to an array....

$files = array();
if($handle = opendir($path)){
    while(false != ($filename = readdir($handle))) {
        if($filename != "." && $filename != ".."){
            $name = preg_replace("/\\.[^.\\s]{3,4}$/", "", $filename);
            $name = str_replace('_', ' ', $name);
            $name = ucwords($name);
            $files[] = $name;
        }           
    }
    closedir($handle);
}
share|improve this answer
1  
Thanks.. so simple.. and exactly what I was looking for.. thank you –  Code Lover Jun 29 '13 at 18:47
    
Yes.. I tried but it wan't allowing me now selected.. –  Code Lover Jun 29 '13 at 19:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.