Code logic problem pulling data from a file / for loop / by array_push

From: Date: Mon, 21 Jan 2002 04:34:51 +0000
Subject: Code logic problem pulling data from a file / for loop / by array_push
Groups: php.general 
Request: Send a blank email to php-general+get-81323@lists.php.net to get a copy of this message
If someone can help with this please examine the following problem... ---------------------------------------------------------------------------- - $lefta = array(); $leftid = array(); $top = count($connarray); //connarray is an array of lines from a file with repeating sections that have values in the form value=setting for ($i=0;$i<$top;$i++) { if (preg_match("/\bleft\b/", connarray[$i])) { array_push($lefta, "$connarray[$i]"); } if (preg_match("/\bleftid\b/", connarray[$i])) { array_push($leftida, "$connarray[$i]"); } } ---------------------------------------------------------------------------- In later sequences I remove everything up to and including the "=" sign which leaves the "setting" under a different array. However, $lefta is not modified itself. After a number of cycles I found a problem. In some cases there is a leftid= that has a name, yet in that section there is no left=. When this form displays the data using a for loop and populating the variables with the $lefta and $leftida I found that when there is no left= nothing gets added to the array. How can I force an addition to the array when the value is not found? Also, this is over-simplified. I'm only showing two values out of the actual search having 15 possible and the number of loops can be 5 sections (more or less) with less than or 15 lines each. I've been swimming around in this code for a while and I'm new to this stuff so my apologies if I my description is hard to follow. Larry S. Brown President/CEO Dimension Networks, Inc. Member ICCA (727) 723-8388

« previous php.general (#81323) next »