UG1234 Posted June 7, 2012 Share Posted June 7, 2012 Hi, can you guys please help. Basically I have populated a variable from lotus database however i want to create a loop to populate an array from the variable, however I just can't get it to work. Here's what I have so far. I have tried 'foreach' and explode functions however just can't get it to work. Any help appreciated. Cheers //get first document in the view $doc = $view->getFirstDocument(); //counter for array $counter=0; //createarray $fieldvalue = array(); //loop while (is_object($doc)) { //get handle to a field called $field $field=$doc->GetFirstItem("[field from db"); //get text value of the fieldstring $fieldstring=$field->text; //echo $fieldvalue; $fieldvalue["$counter"] = array("$fieldstring"); $counter++; $doc = $view->getNextDocument($doc); } $session = null; ?> Link to comment https://forums.phpfreaks.com/topic/263826-populate-array-from-variable-with-each-loop/ Share on other sites More sharing options...
Barand Posted June 7, 2012 Share Posted June 7, 2012 change $fieldvalue["$counter"] = array("$fieldstring"); to $fieldvalue[] = $fieldstring; Link to comment https://forums.phpfreaks.com/topic/263826-populate-array-from-variable-with-each-loop/#findComment-1351949 Share on other sites More sharing options...
UG1234 Posted June 8, 2012 Author Share Posted June 8, 2012 Thanks for the reply. Unfortunately I don't think its worked. I added "print $fieldvalue;" after the loop and I just have an empty array. The result I am hoping for is: $fieldvalue[0] = contain $fieldstring value from 1st loop $fieldvalue[1] = contain $fieldstring value from 2nd loop $fieldvalue[2] = contain $fieldstring value from 3rd loop etc, etc. Any comments appreciated cheers Link to comment https://forums.phpfreaks.com/topic/263826-populate-array-from-variable-with-each-loop/#findComment-1352089 Share on other sites More sharing options...
Barand Posted June 8, 2012 Share Posted June 8, 2012 As it is an array, use print_r($fieldvalue); Link to comment https://forums.phpfreaks.com/topic/263826-populate-array-from-variable-with-each-loop/#findComment-1352096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.