Performance Improvement: Alternative for array_flip function.

Posted by Rachel on Stack Overflow See other posts from Stack Overflow or by Rachel
Published on 2010-03-18T21:49:42Z Indexed on 2010/03/18 22:01 UTC
Read the original article Hit count: 383

Filed under:
|

Is there any way I can avoid using array_flip to optimize performance. I am doing a select statement from database, preparing the query and executing it and storing data as an associative array in $resultCollection and than I have array op and for each element in $resultCollection am storing its outputId in op[] as evident from the code.

I have explained code and so my question is how can I achieve an similar alternative for array_flip with using array_flip as I want to improve performance.

$resultCollection = $statement->fetchAll(PDO::FETCH_ASSOC);

$op = array();

//Looping through result collection and storing unicaOfferId into op array. 
foreach ($resultCollection as $output)
{
$op[] = $output['outputId'];
}

//Here op array has key as 0, 1, 2...and value as id {which I am interested in}

//Flip op array to get unica offer ids as key

$op = array_flip($op);

//Doing a flip to get id as key. 

foreach ($ft as $Id => $Off)
{
    $ft[$Id]['is_set'] = isset($op[$Id]);
}

© Stack Overflow or respective owner

Related posts about php

Related posts about Performance