j4nk3y: reset() von zwei foreach Schleifen

Beitrag lesen

Tag zusammen,

So ich habe mal etwas umgeschrieben und bekomme eine komische Fehlermeldung mit der ich, auch nach längerem suchen, nichts anfangen kann:

	$fraction = ($radius_1 / 50) + 1;
	
	for($a = 0 ; $a <= $fraction ; $a++)
	{
		$b = ($a * 50) + 50;
		
		include('db_connect_function.php');
	
		
	
		$select = "Select id,x,y,z From position 
				WHERE x > $a AND x < $b
				ORDER BY x ASC , y ASC , z ASC";
	
		if($position = $db->query($select))
		{
			
			$objects =  "object_".$a."_".$b;
			
			$$objects = array();
			
			while($object = $position->fetch_assoc())
			{
				array_push($$objects , $object);
			}
			
			echo "$$objects";
			print_r($$objects);
			echo "<br><br>";
			// Close database connection
			
			$db->close();
		}
		else
		{
			log_error_function("","126 , 128",mysqli_error($db),"System");
		}
		
		for($i=0 ; $i<count($$objects) ; $i++)
		{
			$e = $i + 1; 
			
			if($$objects[$e]['x'] == $$objects[$i]['x'] AND $$objects[$e]['y'] == $$objects[$i]['y'] AND $$objects[$e]['z'] == $$objects[$i]['z'])
			{
				include('db_connect_function.php');
				
				$old_object_position_x = $$objects[$e]['x'];
				$old_object_position_y = $$objects[$e]['y'];
				$old_object_position_z = $$objects[$e]['z'];
				
				$same_object_position_x = $$objects[$i]['x'];
				$same_object_position_y = $$objects[$i]['y'];
				$same_object_position_z = $$objects[$i]['z'];
				
				$$objects[$e]['x']=gauss_object_position($radius_1,$center_1['x'],1);
				$$objects[$e]['y']=gauss_object_position($radius_1,$center_1['y'],1);
				$$objects[$e]['z']=gauss_object_position($radius_1,$center_1['z'],1);
				
				$new_object_position_x = $$objects[$e]['x'];
				$new_object_position_y = $$objects[$e]['y'];
				$new_object_position_z = $$objects[$e]['z'];
				
				$object_id_change= $$stars[$i]['star_id'];
				$object_id_same= $$stars[$e]['star_id'];
				
				$change_position = "UPDATE positions SET x=$new_object_position_x , y=$new_object_position_y , z=$new_object_position_z WHERE star_id=$object_id_change";
			
				if($db->query($change_position))
				{
					log_star_position_change("$object_id_same","$object_id_change","$same_object_position_x = $old_object_position_x -> $new_object_position_x","$same_object_position_y = $old_object_position_y -> $new_object_position_y","$same_object_position_z = $old_object_position_z -> $new_object_position_z");
					
					// Close database connection
			
					$db->commit();
				}
				else
				{
					log_error_function("","131 , 133",mysqli_error($db),"System");
				}
				
				break;
				
			}
		}
		
		unset($$objects);
	}

Im Prinzip habe ich folgendes gemacht:

  1. Das Array nach x,y und z sortiert das ich immer nur das Nächste Element untersuchen muss.
  2. Das Array unterteilt, sodass der bereich in dem x liegt maximal 50 Einheiten groß ist.

Das sollte schonmal maßgeblich der Performance zugute kommen.

Jetzt bekomme ich aber in dieser Zeile:

if($$objects[$e]['x'] == $$objects[$i]['x'] AND $$objects[$e]['y'] == $$objects[$i]['y'] AND $$objects[$e]['z'] == $$objects[$i]['z'])

folgende Fehler:

  1. Warning: Illegal string offset 'x'
  2. Notice: Undefined variable: t in
  3. Notice: Undefined variable: s in
  4. Warning: Illegal string offset 'y' in .
    .
    .

Das muss wohl irgendwas mit dem Variablen Arraynamen zutun haben aber ich komme nicht dahinter. vorallem versteh ich nicht wo das t und s herkommen.

Danke für eure Hilfe!

Gruß Jo