|
 |
|
*** Return หลายค่าทำยังไงครับ *** อยาก return ค่าออกจากฟังก์ชั่น หลายๆค่าครับเขียนลักษณะไหน |
|
 |
|
|
 |
 |
|
ทำเป็น อเรย์
|
 |
 |
 |
 |
Date :
2009-09-24 10:05:46 |
By :
reda_008 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
function($ip)
{
$result[0]=shell_exec($ip)
if(ได้)
{
$result[1]="work";
return $result;
}
else
{
$result[1]="not work";
return $result;
}
}
?>
|
 |
 |
 |
 |
Date :
2009-09-24 10:10:01 |
By :
reda_008 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คืนค่าเป็น array, object, serialized object
|
 |
 |
 |
 |
Date :
2009-09-24 10:27:50 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับแต่นึกไม่ออก ช่วยดูอีกรอบนะครับ
Code (PHP)
<?php
function ping($ip)
{
$cmd="ping $ip -n 4";
$result=shell_exec($cmd);
if (stristr($result, 'TTL expired in transit') || stristr($result, 'Destination host unreachable') || stristr($result, 'IP parameter problem') || stristr($result, 'Lost = 4'))
{
$status="not work"; // ผมอยากคืนค่านี้ด้วย เขียนยังไงครับ ช่วยหน่อย
echo "<pre>".$result."</pre>";
return $result; /// ผมคืนค่านี้ได้แล้ว
}
else
{
$status="Work"; //// ส่วนนี้ด้วย
echo "<pre>".$result."</pre>";
return $result; // ผมคืนค่านี้ได้แล้ว
}
}
?>
$time=date("H:i:s");
$log=ping($ip); // ตัวนี้ผมเรียกใช้ฟังก์ชั่น
//// อยากเอาค่า $status มาตรงนี้ครับเพื่อที่จะ insert ใส่ฐานข้อมูล รบกวนช่วยเขียนเพิ่มเติมให้ดูหน่อยครับ
insert("$table","$name","$date","$time","$ip","$log");
|
 |
 |
 |
 |
Date :
2009-09-24 11:19:13 |
By :
chuensanguan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
function ping($ip)
{
$result[0]=$ip;
if($result[0]==123)
{
$result[1]="work";
}
else
{
$result[1]="not work";
}
return $result;
}
$ping_ip = ping(123);
echo $ping_ip[0]; // 123
echo $ping_ip[1]; // work
|
 |
 |
 |
 |
Date :
2009-09-24 13:48:32 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-09-24 14:12:12 |
By :
chuensanguan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|