Inserting array() date into variable.

Here is a little example of what I’m trying to figure out. If anyone could help me out I would be greatly appreciative. I hope I provided enough info in the comments.

$array = array(‘one’, ‘null’, ‘three’, null, ‘five’); // Data gathered from form into an array

 foreach($array as $value) {

    if($value != null) {                                    //I want to list only values inserted from the form
	 $item = "<li>$value </li>";

     $string = "String used by external PHP script <br />     
                       List of items: $item";                                   // I can't seem to get the array data to list here.
                                                                                         // This is only printing the last value in the array.  



You are assigning array values to variable $item within the loop. Therefore at the end of loop (on last iteration) you will have last value from array assigned to $item. Probably you wanted your code work like this:

$array = array(‘one’, ‘null’, ‘three’, null, ‘five’);


foreach($array as $value) {
if($value != null) {
$item. = “

  • $value
  • \n”;

    if($item!="") $item="


    $string = “String used by external PHP script
    List of items: $item”;


    Sponsor our Newsletter | Privacy Policy | Terms of Service