arrayProblems Posted November 25, 2007 Share Posted November 25, 2007 Hey guys, I'm new here. I normally try to figure things out myself and I have googled this, searched forum, and php manual with no luck. It will probably be easy for you guys to tell me what I'm doing wrong, but I'm really new to PHP. First, here's what I'm trying to accomplish: I have a csv file with images stored in directories that I'm trying to import, and define what "type" of images they are. I've so far managed the following... Look inside the field, split into an array using ; as a delimeter, and import. For example: "Detailed Images" Field has something like "c:\images\image1.jpg#alt_text1;c:\images\image2.jpg#alt_text1" So right now I have it working that it will bring in image1.jpg and associate alt_text1, bring in image2.jpg and associate alt_text2. The part where I get stuck is that I'm also trying to say that the first image will be labeled as type "M" main image and everything after will be type "S" secondary images. at first I tried doing something like if (!empty($detailed_file) && match_images('!(.*)', $detailed_file, 1, 0, 1) !== false){ list ($detailed_file, $type) = explode('!', $detailed_file); where I had in the csv "c:\images\image1.jpg#alt_text1!M" to test if it would work, and to no avail. Now I'm thinking the best way to do this would be to somehow say if it is the first array, then $type='M' right? So here is the code I've got so far that does everything I mentioned above. $GLOBALS['import_image_data'] = array( array( 'type' => $type, 'image_alt' => !empty($detailed_alt) ? $detailed_alt : '', 'detailed_alt' => !empty($detailed_alt) ? $detailed_alt : '', ) ); Here is the code that I tried to use, but no go... $GLOBALS['import_image_data'] = array( array( 'type' => $type, 'image_alt' => !empty($detailed_alt) ? $detailed_alt : '', 'detailed_alt' => !empty($detailed_alt) ? $detailed_alt : '', ) ); if array(0) { ["1"]=> $type ='M' } Is this even remotely right? I don't want anyone to write the code for me, I really want to learn how to make this work, and would really appreciate your help! Thank you! -Huy Quote Link to comment 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.