Jump to content
php.lv forumi

Izvilkt no arraya ārā info


Psycke

Recommended Posts

Redz kur ir mans skriptiņš

function rulesdropdown($rules)
{
if ( !is_array($rules) )
	return "";
$response = "<select class='si_rules'>" .
		"<option selected>cvar: value</option>" .
		"<option>---------------------</option>";
foreach ( $rules as $rule )
	$response .= "<option>".substr($rule["rule"],0,20).": ".$rule["value"]."</option>";
return $response . "</select>";
}

Viss kopā strādā ar socketiem, un visi šie arrayi tiek izlikti no servera. Kā, la ies dabonu vienu speciālu arrayu ārā? Nu jā šajā gadījumā katrs arrays saucas 'rule'. Tātād... Kā, lai es dabonu vienu 'rule' ārā no arraya?

Paldies jau iepriekš.

Link to comment
Share on other sites

Kā tieši? Nu tas ir mans skripts tur iekš code tagiem, kurš izvelk informāciju no servera. Visu saliek vienā arrayā un to var aplūkot caur dropdown boxu. Man ir nepieciešams izvilkt dažas rindas ārā no arraya jeb no tā dropdown boxa, lai tās varētu kaut kā dabūt tukšā vietā kā ar echo. Nu es nemāku skaidrāk izskaidrot.

Link to comment
Share on other sites

Neder gan. Nū... Izņemot info ārā no tā arraya, es dabonu šo te:

Array ( [host] => 213.21.217.178:27015 [status] => up [time] => 1182189986 [info] => Array ( [name] => Trick-Jumps.lv Kreedz server [game] => Counter-Strike [version] => 47 [password] => 0 [anticheat] => 0 [os] => l [map] => kz_absolute [bots] => 0 [players] => 9 [slots] => 12 ) [players] => Array ( [0] => Array ( [userid] => 1 [name] => On3 and only | Reinhoolds [kills] => 0 [time] => 00:37:46 ) [1] => Array ( [userid] => 2 [name] => turbiina*/;) [kills] => 0 [time] => 00:10:15 ) [2] => Array ( [userid] => 3 [name] => Potti | Mini_Pro [kills] => 0 [time] => 00:00:51 ) [3] => Array ( [userid] => 4 [name] => pycckue [kills] => 0 [time] => 00:00:49 ) [4] => Array ( [userid] => 5 [name] => MyJIbTuK [kills] => 0 [time] => 00:00:30 ) [5] => Array ( [userid] => 6 [name] => siikais [kills] => 0 [time] => 00:00:48 ) [6] => Array ( [userid] => 7 [name] => Zizu [kills] => 0 [time] => 00:01:08 ) [7] => Array ( [userid] => 8 [name] => 3BEPyGA [kills] => 0 [time] => 00:13:36 ) [8] => Array ( [userid] => 9 [name] => CONTRA|[.:S-pils:.] Acc` [kills] => 0 [time] => 00:01:01 ) ) [rules] => Array ( [0] => Array ( [rule] => _tutor_bomb_viewable_check_interval [value] => 0.5 ) [1] => Array ( [rule] => _tutor_debug_level [value] => 0 ) [2] => Array ( [rule] => _tutor_examine_time [value] => 0.5 ) [3] => Array ( [rule] => _tutor_hint_interval_time [value] => 10.0 ) [4] => Array ( [rule] => _tutor_look_angle [value] => 10 ) [5] => Array ( [rule] => _tutor_look_distance [value] => 200 ) [6] => Array ( [rule] => _tutor_message_character_display_time_coefficient [value] => 0.07 ) [7] => Array ( [rule] => _tutor_message_minimum_display_time [value] => 1 )

un vēl dažas rindas ir klāt.

funkcija rules:

function rules(&$handle,&$result)
{
$challenge = pack("NN", 0xFFFFFFFF, 0xFFFFFFFF);

$response = communicate($handle,A2S_RULES.$challenge);
$control_byte = getchar($response);

if($control_byte == S2C_CHALLENGE)
{
	$challenge = $response;
	$response = communicate($handle,A2S_RULES.$challenge);
	$control_byte = getchar($response);
}

if($control_byte != S2A_RULES)
	return FALSE;

$result = array();

$count = getint16($response);
for($i = 0; $i < $count; $i++)
{
	$key = getstring($response);
	$value = getstring($response);
	$result[] = array("rule"=>$key,"value"=>$value);
}

ksort($result);
return TRUE;
}

Edited by Psycke
Link to comment
Share on other sites

Manuprāt tu man tagad te pasaciņas stāsti! No tavis paša garā teksta saīsinātā veidā:

Array ( [host] => ...
	[status] => ...
	[time] => ...
	[info] => Array ( ... )
	[players] => Array ( ... )
	[rules] => Array ( [0] => Array ( [rule] => ... [value] => ... )
					   [1] => Array ( [rule] => ... [value] => ... )
					   [2] => Array ( [rule] => ... [value] => ... )
					   ...
					 )
   )

Tātad visai acīmredazmi, ka ar $rules['rules'][0], $rules['rules'][1], ... visu var darbūt ārā.

Link to comment
Share on other sites

ka vinsh var radit tukshi vietu, ja pats ieprieksh masivu izvadi, takai to neformatejot :)

Link to comment
Share on other sites

×
×
  • Create New...