dgywft Posted January 15, 2009 Share Posted January 15, 2009 Hey guys, I am having an issue making my own function. I want to run the following function: function getFolder($sku) { if ( (strpos($sku, "P") === 0) || (strpos($sku, "P")) ) { $imgfolder = "print"; } if ( (strpos($sku, "E") === 0) || (strpos($sku, "E")) ) { $imgfolder = "eps"; } if ( (strpos($sku, "T") === 0) || (strpos($sku, "T")) ) { $imgfolder = "type"; } if ( (strpos($sku, "C") === 0) || (strpos($sku, "C")) ) { $imgfolder = "cloth"; } if ( (strpos($sku, "A") === 0) || (strpos($sku, "A")) ) { $imgfolder = "art"; } if ( (strpos($sku, "M") === 0) || (strpos($sku, "M")) ) { $imgfolder = "mm"; } return $imgfolder; } The function will not work as written here: $theImagePath = "/img/". getFolder($sku) . "/" . $sku . "/"; Can anyone provide some pointers on the proper way to run this function as needed? Link to comment https://forums.phpfreaks.com/topic/140914-solved-function-and-return-value-problem/ Share on other sites More sharing options...
Mark Baker Posted January 15, 2009 Share Posted January 15, 2009 So what exactly is it returning, and what are you expecting it to return? Link to comment https://forums.phpfreaks.com/topic/140914-solved-function-and-return-value-problem/#findComment-737557 Share on other sites More sharing options...
dgywft Posted January 15, 2009 Author Share Posted January 15, 2009 This is checking a sku number in my site. It them runs that function with the sku to see what type of product, then set the folder name (mm,print,eps), then return that value at end of function. Then back to my actual page thats running the function, I run it in that statement, then use the variable ($theImagePath) next line in a if statement: - $theImagePath = $serverPath ."/img/". getFolder($sku). "/" . $sku . "/"; if( file_exists($theImagePath) ) { Link to comment https://forums.phpfreaks.com/topic/140914-solved-function-and-return-value-problem/#findComment-737559 Share on other sites More sharing options...
trq Posted January 15, 2009 Share Posted January 15, 2009 What does the $sku variable typically contain? I have a feeling your function could be reduced to.... function getFolder($sku) { $arr = array("P" => "print","E" => "eps","T" => "type","C" => "cloth","A" => "art","M" => "mm"); if (in_array($arr, $sku)) { return $arr[$sku]; } return false; } Link to comment https://forums.phpfreaks.com/topic/140914-solved-function-and-return-value-problem/#findComment-737565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.