emilysnothere Posted March 29, 2012 Share Posted March 29, 2012 Trying to retun an array which gets a file from a directory and then returns the filename as the key and the complete file url as the value but when returning it it prints out "Array" for each file in the directory rather than the file name: Doing this in wordpress. function wsme_select_css_theme(){ $alt_css_template_path = WSME_THEME_CSS; // Define path to files $alt_widgets_template = array(); // set array $out = ''; // Set var if ( is_dir($alt_css_template_path) ) { // If directory exists if ($alt_css_template_dir = opendir($alt_css_template_path) ) { //opens directory while ( ($alt_css_template_file = readdir($alt_css_template_dir)) !== false ) { //if files are in the directory if(stristr($alt_css_template_file, ".css") !== false) { //if the files are .css files $out[] = array($alt_css_template_file => WSME_THEME_CSS.'/'.$alt_css_template_file); //create the array(filename => file path) for each file in the directory } } } return $out; // return array } } array( 'name' => 'Style', 'id' => WS_THEME_PREFIX . '_style', 'headings' => array( array( 'name' => 'Theme CSS', 'options' => array( array('name' => 'Homepage', 'desc' => ' select the css file of the theme you want for your site', 'id' => WS_THEME_PREFIX . '_theme_css', 'value' => '', 'options' => wsme_select_css_theme(), 'type' => 'select' ) ) ) ) Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/259975-help-with-returning-multidimensional-array/ Share on other sites More sharing options...
batwimp Posted March 29, 2012 Share Posted March 29, 2012 If you are trying to print it out, using 'echo' won't print out an array. You need to use print_r() or var_dump() to print out arrays. Quote Link to comment https://forums.phpfreaks.com/topic/259975-help-with-returning-multidimensional-array/#findComment-1332516 Share on other sites More sharing options...
btherl Posted March 30, 2012 Share Posted March 30, 2012 Maybe you want this: $out[$alt_css_template_file] = WSME_THEME_CSS.'/'.$alt_css_template_file; //create the array(filename => file path) for each file in the directory Quote Link to comment https://forums.phpfreaks.com/topic/259975-help-with-returning-multidimensional-array/#findComment-1332595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.