I have a multi dimensional session array in PHP($_SESSION['playlist']['ID1'],$_SESSION['playlist']['ID2'] ETC) with IDs stored as values. In javascript these can be deleted with the press of a button which will relay the value to a function in PHP to tell it to remove that value from the session array by matching the given ID and the one stored in the array. I can't get this to work.
My JS is sending this $(wrapper).append("<?php delVid('"+vidID+"');?> "); but PHP acts like JS is sending a string, which I thought the quotes would make it do anyway but it was the only way I could get the variable to even properly transfer to PHP.
here's my PHP function
function delVid($id){
foreach( $_SESSION['playlist'] as $key => $value ) {
if($id == $value){
unset( $_SESSION['playlist'][ $key ] );
}
sort($_SESSION['playlist'], SORT_NUMERIC);
}
}
ajaxjQuery(document).ready(function($){ var wrapper = $("#playlist-list"); $(document).on("click",".remove", function(){ var vidID = $(this).parent('div').parent('div').attr('id'); $(this).parent('div').parent('div').fadeOut(); $(wrapper).append("<?php delVid('"+vidID+"');?> "); }); });