Solarpitch Posted April 28, 2008 Share Posted April 28, 2008 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 More sharing options...
moselkady Posted April 28, 2008 Share Posted April 28, 2008 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; ?>); Link to comment https://forums.phpfreaks.com/topic/103286-solved-adding-values-to-an-array/#findComment-528980 Share on other sites More sharing options...
GameYin Posted April 28, 2008 Share Posted April 28, 2008 http://us.php.net/manual/en/function.array.php I would highly recommend you read that. Read ALL of it, including the user notes. Link to comment https://forums.phpfreaks.com/topic/103286-solved-adding-values-to-an-array/#findComment-528982 Share on other sites More sharing options...
Solarpitch Posted April 28, 2008 Author Share Posted April 28, 2008 Array's are not my strong point at all.. thanks guys, moselkady that worked fine! Link to comment https://forums.phpfreaks.com/topic/103286-solved-adding-values-to-an-array/#findComment-528984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.