从函数中获取数组并将其转换为变量


Getting An Array from a function and converting it to a Variable

我得到了一个这样的函数,它从客户账户中提取产品数据:

 Am_Lite::getInstance()->getProducts()  

获取aMember产品(product_id=>title)中定义的所有产品的数组

每个客户只有一个产品,所以实际上我不需要数组,但不幸的是,这个函数给出了一个数组,而不是一个变量。

如何将此数组转换为单个变量。请帮忙。

将函数结果分配给一个变量,然后对其进行索引以获得数组元素。

$products = Am_Lite::getInstance()->getProducts();
$product = $products[0];

$singleProduct = Am_Lite::getInstance()->getProducts()[0];