php - Save Indexed Array -
i trying figure out how save indexed array field in database. said, know array can't saved database, can serialize or implode , save. im not sure 1 should using though. don't want collection of items saved in 1 cell. need list of items saved 1 one in column. question need using serialize method, implode or else? here glimpse of code , array trying save.
public function findpolicyids($coverageid = null) { $policyid = $this->policy->find('all', array( 'recursive' => -1, 'conditions' => array('policy.coverage_id' => $coverageid), 'fields' => array('policy.id'))); foreach($policyid $id) { $all[] = $id['policy']['id']; } return $all; } array ( [0] => 5202834f-111c-4a76-8b33-1ed8ae78509d [1] => 5202834f-2ba8-4957-91db-1ed8ae78509d [2] => 5202834f-356c-49a1-beeb-1ed8ae78509d [3] => 5202834f-3b40-453f-a491-1ed8ae78509d
it depends.
this best answer give you.
do whatever like, long doesn't magically corrupt data between write , read.
lemme take moment explore few options on behalf.
- var_export() - might not best idea, securitywise
- serialize() - seems straightforward
- implode() - seems straightforward
- json_encode() - seems straightforward
there other, more obscure, options available. build complex data sets xml, if like.
alternatively, why not normalize schema , add new table present collections of array-data ? normalization tends save bacon in future.
Comments
Post a Comment