Thursday, July 3, 2014

Add an associative array in MySQL result row - PHP





I extract each row from MySQL in PHP, now I want to add an  associative array in each row.
PHP function  array_merge is used.
    public function get_salary() {
        $c = new Connection();

       $items = array("StartTerm" => 0,"EndTerm" => 1000, "sort"=>0, "EmploymentGroup"=>0 );
       while($row = $c->getArray($result)){

// add associate array $row and $items and return it to $results
            $results[] = array_merge($row, $items);    
               }   
        return $results;
     }   

part of code in models in PHP CodeIgniter

No comments:

Post a Comment