Re: adding key-> value pair to an array

From: Date: Wed, 03 Dec 2008 17:07:31 +0000
Subject: Re: adding key-> value pair to an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-284062@lists.php.net to get a copy of this message
Aniketto wrote: > Hi all, > Can anybody tell me how can I add key->value pair in an array. > My code is as follows > > $criteria = array(); > $criteria['mail_subject'] = $form->subject->getValue(); > $criteria['delivery_user_name'] = $form->delivery_user_name->getValue(); > $criteria['start_date'] = $form->start_date->getValue(); > $criteria['end_date'] = $form->end_date->getValue(); > $criteria['group'] = $form->group->getValue(); > > // get table data from database > $rowset = $mailDelivery->findDeliveryMailData($criteria); > > //convert rowset into an array > $mailDataArray = $rowset->toArray(); > if you do a print_r() right here on $mailDataArray, what does it look like? > > if(count($mailDataArray) != 0){ > foreach($mailDataArray as $row){ > $condition['mail_delivery_id'] = $row->id; > $browseCount = $mailDeliveryDetail->findBrowseCount($condition); > $totalCount = $mailDeliveryDetail->findTotalCount($condition); >               //for each row I want to add percentage as new > key->value pair > // but it gives error 'Undefined variable: > percentage' > $row->$percentage = ($browseCount / $totalCount ) * 100; Were you intending to just say $row->percentage instead of calling $percentage? >  } > } > > > Please somebody tell me how to achieve this. > Thanks in advance. > Aniket -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#284062) next »