从zf2中有一行的变量访问数据

I am using object of type Zend\Db\ResultSet\ResultSet which I passed from the controller to a view. Code is given below:

view/districts/index.php:

foreach ($pk_province as $pname) 
{   
    $p_id = $this->escapeHtml($pname->id);
    $p_name = $this->escapeHtml($pname->p_name);     
} 

$pk_province has single record. So I want to access data from it without loop. I tried $p_name = $pk_province->p_name but it gives me undefined variable $d_name.

Any suggestion please.

var_dump($pk_province); shows the following:

object(Zend\Db\ResultSet\ResultSet)#344 (8) {
    ["allowedReturnTypes":protected]=> array(2) { 
        [0]=> string(11) "arrayobject" 
        [1]=> string(5) "array" 
    } 
    ["arrayObjectPrototype":protected]=> object(Admin\Model\Provinces)#312 (3) { 
        ["id"]=> NULL 
        ["p_name"]=> NULL 
        ["inputFilter":protected]=> NULL 
    } 
    ["returnType":protected]=> string(11) "arrayobject"  
    ["buffer":protected]=> NULL 
    ["count":protected]=> int(1) 
    ["dataSource":protected]=> object(Zend\Db\Adapter\Driver\Pdo\Result)#322 (9) {
        ["statementMode":protected]=> string(7) "forward" 
        ["fetchMode":protected]=> int(2) 
        ["resource":protected]=> object(PDOStatement)#316 (1) {
            ["queryString"]=> string(58) "SELECT `provinces`.* FROM `provinces` WHERE `id` = :where1" 
        } 
        ["options":protected]=> NULL 
        ["currentComplete":protected]=> bool(false) 
        ["currentData":protected]=> NULL 
        ["position":protected]=> int(-1) 
        ["generatedValue":protected]=> string(1) "0"  
        ["rowCount":protected]=> int(1) 
    } 
    ["fieldCount":protected]=> int(2) 
    ["position":protected]=> int(0) 
}

You can convert the ResultSet to an array using the ResultSet::toArray method and get the first row from your array:

$array = $resultSet->toArray();
$province = $array[0];

Or you can use the ResultSet::current method to collect the current row:

$province = $resultSet->current();