php array()函式

array()函式是接收一串以逗號為區隔的資料,放入陣列中。

$aLanguages = array("Arabic", 3 => "German", "Korean", "Tagalog");
echo $aLanguages[0] ;   // "Arabic"
echo $aLanguages[3] ;   // "German"
echo $aLanguages[4] ;   // "Korean"
echo $aLanguages[5] ;   // "Tagalog"

若我們沒有指定任何索引值,這些陣列的元素會被指派預設的索引值。要明確指定array()構件中的索引值的話,要用 =>運算子。

PHP-Cookbook-chapte13

程式碼

//'13.1'擷取其他程式的輸出
$session_name = $session_txt['13.1'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";


$current_date = 'date';

$pp =popen('date','r');
while ($line = fgets($pp,1024)){
	$output .=$line;
}
pclose($pp);

show_array($output);
exec('date',$output_1);
print implode ("\n",$output_1)."<br>";  
show_array($output_1);

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   exec()函數。此函式會開啟一個管線連接到某個程式,並將該程式所有的輸出<br>
   逐行放到陣列中(欲填入的陣列當成第二個參數)。
   	
<br>
</fieldset>
";
echo $message."<br>";
//'13.2'印出程式的輸出
$session_name = $session_txt['13.2'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

passthru('date');


$message="
<fieldset><legend><font color=red>TIPS</font></legend>
  passthru()函式 
<br>
</fieldset>
";
echo $message."<br>";