Jump to content

[SOLVED] Function and Return Value - Problem


dgywft

Recommended Posts

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?

 

 

 

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) ) {

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;   

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.