There is a parseDesc() function. As a result of its execution, an array of $productDesc[] is obtained.

Question: How to pull out this array and use it not only in the function itself?

    2 answers 2

    To return the result of the function, you must use the operator return .

    After that, you can assign the result of the function to a variable.

    Example:

     function parseDesc() { return []; } $productDesc = parseDesc(); 

      Dear @Egor Smolyakov @Ipatiev answered your question and this is half the answer. This answer is absolutely correct, if the result of your function is to generate an array of $productDesc But if your function performs another task, and generating an array is a side effect, then you will most likely have to change the format of the output

      Example was

       function parseDesc() { return $result; } 

      It became

       function parseDesc() { return ['result'=>$result,'arr'=>$productDesc]; } $productDesc = parseDesc(); $productDesc = productDesc['arr']; 

      Or use the link in the function, which is fraught with errors when the function is called again

       $productDesc=[] function parseDesc() { &$productDesc=$a; return $result; } 

      But at the design stage, I choose - either this is a function that fulfills the obligation specifically assigned to it, or an entity with its characteristic properties.

      Example

       class ParseDesc{ protected $product_desc=[]; public function doParse(){ $this->product_desc=$a; return $result; } public function getProductDesc(){ return $this->product_desc; } } 

      Application

       $obj= new ParseDesc(); $parser_result=$obj->doParse(); $productDesc=$obj->getProductDesc();