[PHP] adding key-> value pair to an array
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(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; } } Please somebody tell me how to achieve this. Thanks in advance. Aniket -- View this message in context: http://www.nabble.com/adding-key-%3E-value-pair-to-an-array-tp20809115p20809115.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] adding key-> value pair to an array
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(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; } } Please somebody tell me how to achieve this. Thanks in advance. Aniket -- View this message in context: http://www.nabble.com/adding-key-%3E-value-pair-to-an-array-tp20809114p20809114.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php