Php If语句和对象

Php If语句和对象,php,arrays,object,if-statement,scope,Php,Arrays,Object,If Statement,Scope,这是迄今为止我所见过的最奇怪的事情,我完全糊涂了。请有人帮我做这个 $variable=array(); $count=0; // now im am going to loop through a resource that i made while(!feof($job)) { $data=fgets($job); // i am search for different things below. search for nam

这是迄今为止我所见过的最奇怪的事情,我完全糊涂了。请有人帮我做这个

    $variable=array();
    $count=0;
    // now im am going to loop through a resource that i made
    while(!feof($job))
    {
      $data=fgets($job);
      // i am search for different things below. search for name, date, employer
      // i am using regex to search btw
      // presume object in class works fine, and they do.
      if(search for eg name in $data, storing in $variable[$count].first($match))

      // the problem is at this point i will have access to 
      // $variable[$count].getFirst(returns value set by first) which was set above;  

      if(search for eg Employer in $data, storing in variable[$count].next($match))

      // i will have access here as well 
      // $variable[$count].getFirst(returns value set by first) which was set above

      if(search for 3rd search in $data, storing in variable[$count].name($match))

      // down here after the second if i am not able to see any of my variables set more than 2 if statements ago????
      // $variable[$count].getFirst(does not returns the value set by first()) which was set                                                          above

      if(search for 4th search in $data, storing in variable[$count].foo($match))
      // check if everything is set then count++;
    } 
现在,这些方法中的每一个都完全依赖于下一个,但在2个if语句之后。我只是无法访问$variable[count]->getfirst() 答案是空的

编辑

这是实际代码


变量[$count]。下一个($match)

.next()将内部指针移动到数组中的下一个元素。

实际发布一些真实代码可能是值得的,这样我们就能更清楚地看到问题所在。我已经更新并发布了代码。它真的很长,所以我把它剪短了
require "functions/decodeEncodedUrl.php";
require "objects/jobObject.php";
$url=decodeEncodedUrl();
$profile=array();
$companies=0;
$url_search='http://www.jobbank.gc.ca/';
$startReading=0;
$job=fopen($url['url'], 'r')or die("JobBanks is failing to respond.<br>Please Try again Later");
while(!feof($job))
{
  set_time_limit(500);
  $profile[$companies]= new jobProfile();
  $trash=fgets($job);
  if(!$startReading)
  {
    if(preg_match('~RepeaterSearchResults_hypJobItem_[0-9]+~',$trash,$matches))
    {
      $startReading=true;
    }
  }
  if($startReading)
  {
    $data=$trash;
    if(preg_match("~href=\".*\"~",$data,$matches))
    {
      $temp=preg_replace("~href=~",'',$matches[0]);
      $temp=preg_replace("~\"~",'',$temp);
      $profile[$companies]->setLink($url_search.$temp);
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~>[A-Za-z-, ]+\(~",$data,$matches))
    {
      $temp=preg_replace("~>|\(~",'',$matches[0]);
      $profile[$companies]->setPosition(ucfirst($temp));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~# *[0-9]+~",$data,$matches))
    {
      $profile[$companies]->setOrderNum(preg_replace("~#| ~",'',$matches[0]));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~Employer:</strong>.*~",$data,$matches))
    {
      $temp=preg_replace("~Employer:</strong>&nbsp;~",'',$matches[0]);
      $temp=preg_replace("~<br.*~",'',$temp);
      $temp=ucfirst($temp);
      $profile[$companies]->setEmployer($temp);
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~[$][0-9]+.*~",$data,$matches))
    {
      $temp=preg_replace("~/.*~",'',$matches[0]);
      $profile[$companies]->setSalary(preg_replace("~[$]~","$ ",$temp));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~[$][0-9]+.*~",$data,$matches))
    {
      $temp=preg_replace('~[$A-Za-z0-9. ]*[/] ?~','',$matches[0]);
      $profile[$companies]->setRate(preg_replace('~<.*~','',$temp));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~Location:.*~",$data,$matches))
    {
      $temp=preg_replace('~.*;~','',$matches[0]);
      $temp=preg_replace('~^ |,~','',$temp); 
      $profile[$companies]->setCity(ucfirst($temp));
      //echo ucfirst($temp)."<br>";
    }
    if(preg_match("~Location[:<>/\,A-Za-z ]*~",$data,$matches))
    {
      $profile[$companies]->setProvince($matches[0]);
      //echo " ".$matches[0]."<br>\n";
      //echo $profile[$companies]->getLocation()."\n<br>";
    }
    if(preg_match("~[0-9]{4}/[0-9]{2}/[0-9]{1,2}~",$data,$matches))
    {
      echo $profile[$companies]->displayHTML();
      $profile[$companies]->setDate($matches[0]);
      if($profile[$companies]->allDataSet())
      {
        //echo "data was set"."<br>";
        $startReading=false;

        $companies++;
      }
      else
      {
        $startReading=false;
        $companies++;
        echo "Data was Not set";
      }
    }
  }
}
fclose($job);
If
{
//Profile[number] info stored
}
if
{
//Profile[number] info available
}
if
{
//profile[number] info available
}
if
{
//profile[number] info is gone
}