Ok this is probably really simple and I just can not figure it out! I need to grab the value from an array in foreach loop in php and pass it into an array fro jquery. Here is my code:
foreach ($results as &$value) {
$vall[] = $value.", ";
}
$result = count($results);
echo $result;
print_r($vall);
This prints out a normal array = Array ( [0] => one.jpg, [1] => two.jpg, [2] => three.JPG, [3] => four.JPG, )
I need it to create an array like this: one.jpg, two.jpg, three.JPG, four.JPG (only the values) Then I need to pass that to my jquery:
$(".next").click(function(){
var p = [<?php echo $vall ?>];
var start = id;
var next = p[($.inArray(start, p) + 1) % p.length];
var prev = p[($.inArray(start, p) - 1 + p.length) % p.length];
$(".cont").append(next);
$(".cont").append(prev);
});
**I also need to take the comma off of last value.. any help or alternatives to get this done would be greatly appreciated.
Why not take the far simpler route and use
json_encode()?Replace this…
with this….
and you can get rid of your entire foreach loop.