We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to find the result set in one attribute

I want to achieve a similar effect as follows:

    $findResult = array(
        0 => array(
        'id' => 1,
        'name' => 'vendor',
        'sex' => 1
        ),
        1 => array(
        'id' => 1,
        'name' => 'vendor',
        'sex' => 1
        ),
    );

Such as this is the result of find back. I think in this result always add in one unit Like this: $findResult[0]['age'] = 18; $findResult[1]['age'] = 20;

Because the find the returned result set is a one-to-one correspondence table field, and I want to add this attribute is not secondary personal name of paragraph, so I can't increase, do you have any other methods.



98.9k
Accepted
answer

Change the hydration mode:

$robots = Robots::find();

//Return every robot as an array
$robots->setHydrateMode(Resultset::HYDRATE_ARRAYS);

foreach ($robots as $robot) {
    echo $robot['year'], PHP_EOL;
}

https://docs.phalcon.io/en/latest/reference/models.html#hydration-modes



20.5k

Why I did not respond to a click on the Reply -- can't Reply you!