Jump to content
php.lv forumi

masiivu internal pointer


andrisp

Recommended Posts

ir piemeeram shaads kods:

$columns = 3;
foreach($array as $value) {
  echo '<tr>'."\n";
  echo '<td>'.$value.'</td>'."\n";
  for($x=1;$x<$columns;$x++) {
	 echo '<td>'.next($array).'</td>'."\n";
  }
  echo '</tr>'."\n";
}

 

ideja taada, ka gribeejaas veertiibu drukaashanu tabulaas, izmantojot internal pointer paarvietoshanu, bet nezkaapeec sheit:

foreach($array as $value)

tiek ignoreets tas, ka ar next() tiek pointers pastumts uz priekshu..

 

kaapeec taa ?

 

UPDATE:

rekaa - http://lv.php.net/manual/en/function.next.php#41622

 

jaapameegjina pasham uzrakstiit savu foreach, kur tiek muuvots internat pointers. :)

 

UPDATE2:

uztaisiiju shaadu:

while(false !== current($array)) {
 echo '<tr>'."\n";
for($x=0;$x<$columns;$x++) {
	if (false !== current($array)) {
		echo '<td>'.current($array).'</td>'."\n";
		next($array);
	} else {
		echo '<td></td>'."\n";
	}
}
 echo '</tr>'."\n";
}

 

izskataas, ka straada tiiri ok..

Edited by andrisp
Link to comment
Share on other sites

×
×
  • Create New...