hi everyone,
i need help on this issue,
i have an array and i would build something like this:
for ($obj in $target["a","b","c"]πŸ˜‰
{
if ($obj=$target["a"])
{$msg="caution";}
elsif($obj=$target["b"])
{$msg="alert";}
else {$msg="warning";}
foreach ($goal as $obj)
{
print $goal;
print $msg;
}

wich is the correct syntax?
Is there a way to code it fatest?
Thank's a lot in advance and sorry for my English!!!!!!!

    For one, $obj will always equal $target["a"]. You are not setting your if, else statements correctly.

    It should read:

    if ($obj == $target["a"])
    {your output here}

    You are not testing for a comparison in your code...

      yes it's correct, i wrote "=" instead of "==", but what about the rest? it's correct?

        I don’t for sure understand what are you mean but maybe use switch function will be right instead of if function

          i'm sure switch work better then "if-elseif-else" in this case, but my problem is not there, i need a good way to write the first "for" statement, i'm receiving an error on that line!!!
          any ideas?

            I can't understand you maybe if give me the idea which your work maybe I find the solution

              OK,
              I have several servers, each one run a service such as pop,smtp,http.
              pop servers are pop1,pop2,pop3 ecc
              http serve are web1,web2,web3 ecc
              smtp server are smtp1,smtp2,smtp3 ecc
              i create an array like this:
              $target= array (
              "smtp" => array ("1"=>"smtp1.csi",
              "2"=>"smtp2.csi",
              "3"=>"smtp3.csi",
              )
              "pop" => array ("1"=>"pop1.csi",
              "2"=>"pop2.csi",
              "3"=>"pop3.csi",
              )
              "web" => array ("1"=>"web1.csi",
              "2"=>"web2.csi",
              "3"=>"web3.csi",
              )
              );

              I want to monitor services for every server on specific port with:
              $fd=fsockopen($host,$port,$errno,$errstr,10);

              If i use foreach three times it's easy
              example:
              foreach($target["smtp"] as $host){
              $port="25";
              $fd=fsockopen($host,$port,$errno,$errstr,10);
              if (!$fd) {
              $color="red";
              $msg="not active";
              }
              else {
              $color="green";
              $msg="active";
              fclose ($fd);}
              //then i change target and port for two times, but in this way i have to use function foreach three times.
              Now, what kind ok structure i need to use only one time the functio foreach?
              I hope i explained good my problem?

                if you have php 4.0.6
                Try:
                while(isset(array_search($obj,$target)))
                {
                your code here
                }
                instead of: for ($obj in $target["a","b","c"]πŸ˜‰

                If you don't have php 4.0.6 here is a neutered version of a function I wrote a long time ago:

                function findinarray($searchvalue,$array)
                {
                if(isset($array))
                {
                do{ if (current($array) == $searchvalue){ return TRUE;}}
                while (next($array));
                }
                else { return "null"; }
                }

                while("null" != findinarray($obj,$target))
                {
                your code here
                }

                  i have php 4.0.6 but the first statement oyu suggest doesn't work, i receive an error like this:
                  Parse error: parse error, expecting T_VARIABLE' or'$'' in c:\programs\apache group\apache\htdocs\testmon.php on line 61, which is the line
                  while(isset(array_search($obj,$target)))

                    I'm terribly sorry,
                    while(array_search($obj,$target))
                    {
                    // your code here
                    }
                    isset() is not needed

                    You will have to change the value of $obj in your code or you'll end up with an infinite loop (always fun!)

                      i'm not sure but array_search is not a function, i'm running apache 1.3.19 and php 4.0.6 under win2000 , i search array_search also on www.php.net but i couldn't find it!!!

                        Write a Reply...