Jump to content

[SOLVED] Adding values to an array?


Solarpitch

Recommended Posts

Hey,

 

I have a piece of code that will set a "callimage" variable if the image is not set as "blank". What I want to do is add all the images that are not equal to "blank" into a JS array.

 


<?php 


.... 		if($image1 != "")
	{
		 $callimage1 =  "http://site.com/admin/".$e[8];
	}


	if($image2 != "")
	{
		 $callimage2 = "http://site..com/admin/".$e[9];
	}


	if($image3 != "")
	{
		$callimage3 = "http://site..com/admin/".$e[10];
	}

?>


// this is how I am trying it at the min but its adding all the images that are set to blank...

var Slides = new Array('<?php print $callimage1; ?>','<?php print $callimage2; ?>','<?php print $callimage3; ?>');

Is there a way I can add values to the array only if the callimage variables are set?




Link to comment
https://forums.phpfreaks.com/topic/103286-solved-adding-values-to-an-array/
Share on other sites

 

Try this:

 

<?php 


.... 		if($image1 != "")
	{
		 $callimage1 =  "http://site.com/admin/".$e[8];
		 $img[] = "'$callimage1'";
	}


	if($image2 != "")
	{
		 $callimage2 = "http://site..com/admin/".$e[9];
		 $img[] = "'$callimage2'";
	}


	if($image3 != "")
	{
		$callimage3 = "http://site..com/admin/".$e[10];
		 $img[] = "'$callimage3'";
	}
	$images = join(",", $img);

?>

var Slides = new Array(<?php print $images; ?>);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.