boisterouslobster
boisterouslobster

Reputation: 1293

Array values not being processed

I put together some code to process the values in an array. However, it appears that only the first line is being printed out. I can verify that the array has a size of 247 (by including a sizeof() check before the loop).

Is there something I am not seeing here? The declaration of my $title variable is :

$title = array();

on a global scope.

function pushTitleChanges()
{
  global $title, $first_name, $last_name;
  $index = 0;

  print_r($title);
  if(is_array($title))
  {
    for($x =0; $x< sizeof($title);$x++)
    {
        echo "The index is " . $index .' '. "and title size is " . sizeof($title);
        echo "<br/>";

        $title = str_replace(array('.', ','), '' , $title[$index]);

        $statement = "UPDATE guest_list_guests
        SET guest_list_guests.title = '{$title}'
        WHERE guest_list_guests.first_name ='{$first_name[$index]}'
        AND guest_list_guests.last_name = '{$last_name[$index]}';";
        $index++;
    }
  }
}

Upvotes: 0

Views: 45

Answers (1)

Hurricane Development
Hurricane Development

Reputation: 2464

You are setting the entire title array to `str_replace(array('.', ','), '' , $title[$index]);' This is overwriting the entire array with a String when it seems you want to only change that index. Hence that line would really be:

 $title[$index] = str_replace(array('.', ','), '' , $title[$index]);

I also recommend using the $x variable you have created, it stores the same value as $index making $index completely unnecessary.

Upvotes: 2

Related Questions