In my code I'm trying to call a function that is inside of another function. I'm trying to pass the $results var to the NVPToArray() function and return the result. After that, I want to echo the result, which will be an array. I keep getting an error saying that the function is undefined so I'm pretty sure that I'm not calling the function properly.
<?php
class Process extends BaseController {
// Function to convert NTP string to an array
public function postPurchase() {
// Include config file
include(app_path().'/includes/paypal_config.php');
$result = curl_exec($curl);
curl_close($curl);
// Parse the API response
$nvp_response_array = parse_str($result);
// Function to convert NTP string to an array
function NVPToArray($NVPString)
{
$proArray = array();
while(strlen($NVPString))
{
// name
$keypos= strpos($NVPString,'=');
$keyval = substr($NVPString,0,$keypos);
// value
$valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
$valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
// decoding the respose
$proArray[$keyval] = urldecode($valval);
$NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
}
return $proArray;
}
NVPToArray($this->$result);
echo $proArray;
}
}
?>
NVPT
notNVPToArray()
... also, I recommend against nesting functions like that as it makes code much less readable. – John C Jul 5 at 1:12NVPT()
was a typo in your original post? – faintsignal Jul 5 at 1:18