php - How can I run a function with an array of checkbox values passed as an argument?
So I'm wanting to run a function EVERY TIME a user clicks thebtnChangeCat
button...Im having trouble and I'm really not sure how to get it to work!
Im trying to runshowCategory($_POST['chkCat'], 1)[0];
and pass it the array of checked checkboxes when the user clicks thebtnChangeCat
button. Im not sure why this isn't working??
I've literally searched everywhere for a WORKING solution but can't find one that will work when passing the values to a function!
$showVideos = showCategory($categories, 1)[0];
$rowLength = showCategory($categories, 1)[3];
$likes = showCategory($categories, 1)[1];
$dislikes = showCategory($categories, 1)[2];
?>
<main>
<div class='controller-wrap'>
<div class='content-wrap'>
<h3>Category: </h3>hp
<form action='most-liked.php' method='post'>
<?php
$allCategories = ["All", "Sport", "Automotive", "Comedy", "Misc", "Surfing"];
$htmlOutput = "";
$i=0;
for($i;$i<sizeof($allCategories);$i++)
{
if($allCategories[$i] == "Surfing"){
$htmlOutput .= "<input selected type='checkbox' name='chkCat[]' value='".$allCategories[$i]."'/>";
}
else{
$htmlOutput .= "<input type='checkbox' name='chkCat[]' value='".$allCategories[$i]."'/>";
}
}
echo $htmlOutput;
?>
</form>
<br />
if(isset($_POST['chkCat'])){
if(is_array($_POST['chkCat'])) {
foreach($_POST['chkCat'] as $value){
echo $value;
}
}else{
$value = $_POST['chkCat'];
echo $value;
}
// showCategory($_POST['chkCat'], 1)[0];
}
isset($_POST['btnChangeCat'])){
// //How can I run this function with the array of CHECKBOXES??
showCategory($_POST['chkCat'], 1)[0];
}
?>
<input type='submit' value='CHANGE CATEGORIES' class='btnlike btnLike' name='btnChangeCat'/>
</div>
</main>