Rakesh Bitling
Rakesh Bitling

Reputation: 39

PHP Push elements into array

Hello Friends My Code is as Follow: Here I am iterating over for loop

foreach($row_result as $results)
{
  $f = fopen("jigsaw.csv", "a+");
  $new_array = array();
  $content = $results->findElement(WebDriverBy::className('seo-company'))->geTtext();
  $test = array();
  if($i==1)
  {
    $Orgnisation_name = $content;
    $concate = array_push($test,$Orgnisation_name);
    echo "\n";
  }  
  if($i==2)
  {
    echo $Website = $content;
    echo "\n";
  }  
  if($i==3)
  {
    echo $HeadQuarters = $content;
    echo "\n";
  }  
  if($i==4)
  {
    echo $Phone = $content;
    echo "\n";
  }  
  if($i==5)
  {
    echo $Industries = $content;
    echo "\n";
  }  
  if($i==6)
  {
    echo $Employees = $content;
    echo "\n";
  }  
  if($i==7)
  {
    echo $Revenue = $content;
    echo "\n";
  }  
  if($i==8)
  {
    echo $Ownership = $content;
    echo "\n";
  }  
  $i++;
} 

Upvotes: 0

Views: 92

Answers (2)

aland
aland

Reputation: 2004

Do you need to use array_push? $concate = array_push($test,$Orgnisation_name); $test is blank at this point. If you just want to add an item to the $concate array, $concate[] = $Orgnisation_name; is enough.

Upvotes: 1

Viacheslav Kondratiuk
Viacheslav Kondratiuk

Reputation: 8879

array_push return value is:

Returns the new number of elements in the array.

So 1 is the number of elements in array.

Seems that you will always have 1, because you call $i++ and according to your code, block with array_push will be executed once.

Upvotes: 2

Related Questions